Express - Static Files
Created : August 24, 2020
// Serve static files in a directory named 'public' app.use(express.static('public'));
- To use multiple static assets directories, use
- Express looks up the files in the order in which you set the static directories.
- To create a virtual path prefix where the path does not actually exist in the file system, specify a mount path for the static directory.
Load the files from the
- The path is relative to the directory.
- It’s safer to use the absolute path of the directory.
const path = require('path'); app.use('/static', express.static(path.join(__dirname, 'public')));