Named routes in Django-style

suggest change

Express does not name routes. express-reverse adds a name and can build the URL later with app.locals.url('test'):

npm install express-reverse

Plug it in your project:

var app = require('express')();
require('express-reverse')(app);

Then use it like:

app.get('test', '/hello', function(req, res) {
  res.end('hello');
});

express.Router() does not receive these names. Pass app into the router factory, as in the Express routing guide:

require('./middlewares/routing')(app);

And use it like:

module.exports = (app) => {
    app.get('test', '/hello', function(req, res) {
      res.end('hello');
    });
};

The same app.get(name, path, handler) form is how you attach a name and a path to a controller function.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents