Named routes in Django-style
suggest changeExpress 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents