I am trying to iterate thru array of objects and add some stuff inside these objects using async function in Node.js.
So far my code looks like:
var
Use async.each
async.each(channel, function(entry, next) {
knex('albums')
.select(knex.raw('count(id) as album_count'))
.where('channel_id', entry.id)
.then(function (terms) {
var count = terms[0].album_count;
entry.attributes["totalAlbums"] = count;
next();
});
}, function(err) {
console.log("I want this to be printed once the foreach is finished");
res.json({error: false, status: 200, data: channel});
});
The final callback will be called when all entries are processed.