If you want to put the routes in a separate file, for example routes.js
, you can create the routes.js
file in this way:
module.exports = function(app){
app.get('/login', function(req, res){
res.render('login', {
title: 'Express Login'
});
});
//other routes..
}
And then you can require it from app.js
passing the app
object in this way:
require('./routes')(app);
Have a look at these examples: https://github.com/visionmedia/express/tree/master/examples/route-separation
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…