From a given controller (productController), how to res.render results (all categories and stores) provided from several DAOs (categoryDao and storeDao)?
I would like to avoid nested callbacks like these:
// productController.js
var categoryDao = require ('./categoryDao.js');
var storeDao = require ('./storeDao.js');
categoryDao.allCategories(function(err, categories) {
storeDao.allStores(function(err, stores) {
res.render('edit', {allCategories : categories, allStores : stores});
});
});
Given that I'am following this in order to reuse categoryDao in other controllers.
// categoryDao.js
var Category = mongoose.model('Category');
exports.allCategories = function(callback) {
Category.find().exec(function(err, categories) {
console.log(categories);
callback(err, categories);
}
}