Categories
JavaScript Answers

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

Spread the love

Sometimes, we want to set up two different static directories with Node.js Express framework.

In this article, we’ll look at how to set up two different static directories with Node.js Express framework.

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

To set up two different static directories with Node.js Express framework, we can call express.static and app.use with different static file paths.

For instance, we write

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

to expose the /public URL path to __dirname + "/public" with express.static.

Likewise, we expose the /public2 URL path to __dirname + "/public2" with express.static.

Conclusion

To set up two different static directories with Node.js Express framework, we can call express.static and app.use with different static file paths.

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 *