I've recently started a Nodejs project and my roads look like this :
router.get('/groups/', function(req, res) {
GroupManager.getAllGroup(function(groups) {
return res.json(groups);
});
});
I saw few example of people separating their routes and the function handling them, leading to something like :
GroupController.js
exports.module = {
getAll : function(fn) {
GroupManager.getAllGroup(function(groups) {
fn(groups);
}
}
}
Routes.js
router.get('/groups/', function(req, res) {
GroupController.getAll(function(groups) {
return res.json(groups);
});
});
The project I'm starting is growing pretty fast so it's very important for me to have a clean codebase, but I struggle to find the benefit of this way of splitting the code.
Also, I'm struggling trying to find some documentation about code organisation under expressJS. I found many blog post discussing it, but nothing that made authority, is there some famous open-source expressJs project I could use as inspiration ?
Aucun commentaire:
Enregistrer un commentaire