How to run a function after an async function completed in node.js?

Viewed 8349

I want to run a code after my forEach loop.

myPosts.forEach(function(post) {
    getPostAuthor(post.authorID, function(postAuthor) {
        post.author = postAuthor;
    }
});

res.render('index', {
    posts: myPosts
});
res.end();

in code above first res.render runs and after that forEach fills the post.author

6 Answers
Related