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.use(express.static('public'))
/* ... */
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
)
→ Here's my latest YouTube video
→ Get my Express.js Handbook
→ I wrote 17 books to help you become a better developer, download them all at $0 cost by joining my newsletter
→ JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025