Static files
Nest 10 / 11 / 12 · Node 22+ / Bun 1.4+
Packed consumers cover static assets on Nest 10/11/12 and Node/Bun: cache
validators, HEAD, partial and unsatisfiable ranges, stale If-Range,
preconditions, directory redirects/indexes, hidden files, controller
fallthrough and concurrent range requests.
app.useStaticAssets(root, options) behaves like express.static(), which
Nest’s Express adapter uses:
ETagandLast-Modifiedvalidators.If-None-MatchandIf-Modified-Sinceget304. A failedIf-MatchorIf-Unmodified-Sincegets412.- Single byte ranges get
206, and unsatisfiable ones get416. Several ranges, a malformed header or a staleIf-Rangesend the whole file, as insend. Cache-Control: public, max-age=…frommaxAgein milliseconds or a duration such as"1d", plusimmutable.- Dotfiles are hidden by default (
dotfiles: "allow" | "deny" | "ignore"). - A directory requested without its trailing slash gets a
301redirect. index,extensions,setHeaders,fallthrough,etag,lastModified,cacheControlandacceptRangeswork as inexpress.static().- The adapter matches
prefixper path segment, case-insensitively, like an Express mount path./assetsserves/assets/app.jsbut not/assetsapp.js.
Content types come from a built-in table that matches Express for common web
files. The adapters send other extensions as application/octet-stream. They
stream files from disk without buffering them. On Bun, a full file sent in
response to a request with a Range header has no Content-Length when it is
larger than 1 MiB, because Bun would otherwise apply the range itself.
Point the root only at public assets. For high-volume delivery, use a CDN.