The function signature is: express.static(root, [options])
Now, you can load the files that are in the public directory:
Express looks up the files relative to the static directory, so the name of the static directory is not part of the URL. To use multiple static assets directories, call the express.static middleware function multiple times:
Express looks up the files in the order in which you set the static directories with the express.static middleware function. For best results, use a reverse proxy cache to improve performance of serving static assets.
To create a virtual path prefix (where the path does not actually exist in the file system) for files that are served by the express.static function, specify a mount path for the static directory, as shown below:
Now, you can load the files that are in the public directory from the /static path prefix.
However, the path that you provide to the express.static function is relative to the directory from where you launch your node process. 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:
app.use(‘/static’, express.static(path.join(__dirname, ‘public’)))