Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 232
sNiCKY Avatar asked May 12 '11 04:05

sNiCKY


1 Answers

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

like image 199
facetcounter Avatar answered Sep 25 '22 12:09

facetcounter