express.static() is built-in middleware that serves files from a folder — CSS, JavaScript, images, fonts, and HTML. It is based on serve-static. Mount it with app.use() and Express maps the request path onto that root directory.
The folder name is not part of the URL. With app.use(express.static('public')), a file at public/css/style.css is available at /css/style.css. Prefer an absolute root (for example path.join(__dirname, 'public')) so the app works no matter which directory you start Node from.
Syntax
Call express.static in your Express.js app. Start with this line.
Express
express.static(root, [options])
Call
What it does
express.static(root, [options])
Primary signature.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
File on disk: public/css/style.css
GET http://localhost:3000/css/style.css
→ 200 (file contents)
GET http://localhost:3000/public/css/style.css
→ usually misses (folder name is not part of the URL)
How It Works
Pick an absolute root.path.join(__dirname, 'public') stays correct even if you start Node from another directory.
Mount without a prefix.app.use(express.static(…)) maps / onto that folder.
URL = path inside the folder.public/css/style.css → /css/style.css.
No manual route needed. The middleware sends the file when it exists.
Example 2 — Virtual Path Prefix
Serve the same folder under a URL prefix such as /static.
GET /css/style.css (found in public/)
→ 200 + Cache-Control: public, max-age=86400
GET /readme.txt (only in files/)
→ public miss → next() → files/ hit → 200
How It Works
Pass options on the first mount.maxAge: '1d' tells browsers they may cache for a day.
Search order matters. Express tries public first, then files.
Default fallthrough helps stacking. A miss in the first folder calls next() so the second can run.
Production tip. For heavy traffic, put a reverse proxy or CDN in front of these assets.
Compatibility
Runtime Support
express.static() is Express.js built-in middleware. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only download the files it serves.
✓ Server · Express 4 & 5
express.static()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
express.static()Express on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Create a public folder, copy a snippet, and start the server with node.
Frequently Asked Questions
It is built-in middleware that serves files from a root folder. Express maps the request URL onto that folder and sends the file when it exists.
No. With app.use(express.static('public')), public/css/style.css is served at /css/style.css — not /public/css/style.css.
Mount with a path: app.use('/static', express.static('public')). Then files are available under /static/...
By default (fallthrough: true), the middleware calls next() so later routes or other static folders can handle the request.
No. It runs on your Node.js server. Browsers only request the asset URLs your middleware serves.