Serving Static Assets with Express

How to serve static assets directly from a folder in Express

It’s common to have images, CSS and more in a public subfolder, and expose them to the root level:

const express = require('express')
const app = express()


/* ... */

app.listen(3000, () => console.log('Server ready'))

If you have an index.html file in public/, that will be served if you now hit the root domain URL (http://localhost:3000)

Download my free Express.js Handbook and check out my Node.js Masterclass!

👀 Looking for a job? look at DEVJOBS (BETA) 🔥