Expressjs order of app.router and express.static Expressjs order of app.router and express.static angularjs angularjs

Expressjs order of app.router and express.static


It is the best to explain with an example. Let's say, you have an en.json file and you also have a route:

app.get('/en.json', function(req, res) {    res.send('some json');});

If you put

app.use(app.router);

before

app.use(express.static(__dirname + '/public'));

router will have a priority over static file, and user will see some json, otherwise en.json file will be served.

So if you don't have such collisions it doesn't matter which order you choose.

P.S. Note that if you're using Express 4 you may see this error:

Error: 'app.router' is deprecated!Please see the 3.x to 4.x migration guide for details on how to update your app.

On the wiki page @HectorCorrea has shared in comments there is an explanation of this error:

no more app.use(app.router)All routing methods will be added in the order in which they appear

Hope this helps