I need to do a few independent database queries in Node.js. After all queries are executed, response should be sent. My first try looks like this:
templateDa
Use the async package: (npm install async
)
async.parallel([
function(){ ... },
function(){ ... }
], callback);
https://github.com/caolan/async#parallel
Alternatively, you can use promises:
Q.spread(
[ model.getA(), model.getB(), model.getC() ],
function(a, b, c) {
// set templateData
return templateData;
}
).then(...);
(assuming that the get*()
methods return promises)