I am using express and async.js for a node application. I have this code in my app.js:
var resultObject = {};
app.get('/average', function(req, res) {
async.series([
function(callback) {
//This does some complex computations and updates the resultObject
routes.avg(req.query.url, resultObject);
console.log('1');
callback();
}
,
function(callback) {
res.send(resultObject);
console.log('2');
callback();
}
]);
});
The problem is that the res.send(...) fires before the complex computation in the first function finishes. Therefore, the object sent is empty. Is there some error in my code, or am I not using async.js correctly?