Say i have this code to separate routes in expressjs:
module.exports = function(express,app,client) {
app.get('/', function(req,res,next) {
var query = 'SELECT * FROM users LIMIT 10';
var user = client.query(query, function (err, results, fields) {
res.render('index', {
title: 'test',
users: results
});
client.end();
});
});
}
And require it in app.js
:
require('./controllers/routes.js')(express,app,client);
1) How do i separate db queries into new files in the best way?
This file would get pretty big even if i separate db logic.
2) What is a good way to separate routes? Maybe separate modules? and then require them all in app.js
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…