Categories
JavaScript Answers

How to set up two different static directories in Node.js Express framework?

Spread the love

To set up two different static directories in Node.js Express framework, we call express.static.

For instance, we write

app.use("/public", express.static(__dirname + "/public"));
app.use("/public2", express.static(__dirname + "/public2"));

to call express.static to return 2 middlewares toi server the /public and /public2 folders as static directories.

And then we call app.use to use the middlewares to make the folders available via the /public and /public2 URLs.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *