Lesson 17 / 23

express.static()

Hand out images, CSS, and built frontend assets from a folder.

A built-in file server

express.static(root) returns middleware that serves any file under root matching the request path — no route needed per file.

Serving a public folder

A file at public/logo.png becomes reachable at /logo.png.

app.use(express.static('public'));
// public/logo.png -> GET /logo.png
// public/index.html -> GET /

Custom mount path

Add a prefix so files live under /static/* instead of root: app.use('/static', express.static('public')).