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.