Basic Node and Express: Serve Static Assets with file directory

Viewed 33
2 Answers

Use:

app.use(express.static('./public'));

As described in express documentation:

If you run the express app from another directory, it’s safer to use the absolute path of the directory that you want to serve:

const path = require('path')
app.use('/static', express.static(path.join(__dirname, 'public')))
Related