Setting up two different static directories in node.js Express framework


Question

Is it possible? I would like to set up two different directories to serve static files. Let's say /public and /mnt

1
90
5/12/2011 4:53:58 AM

You can also set the path that static files will be served to the web from by specifying an additional (first) parameter to use() like so:

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

That way you get two different directories on the web that mirror your local directories, not one url path that fails over between two local directories.

In other words the URL pattern:

http://your.server.com/public/*

Serves files from the local directory public while:

http://your.server.com/public2/*

Serves files from the local directory public2.

BTW this is also useful if you don't want static to serve the files from the root of your server but rather from a more qualified path.

HTH

141
11/25/2013 9:58:28 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon