Home node.js: Async.parallel, callback is not a function
Reply: 0

node.js: Async.parallel, callback is not a function

user1147
1#
user1147 Published in June 20, 2018, 7:22 am

So I want to get the amount of viewers from each subforum. I wanted to do this by using async.parallel and then receiving the results at the end. The problem is that I want to call the same function 4 times (one time for each subforum) with a different argument. How do I do this? The way you see it below is how I tried to do it, but it gave me an error that 'callback is not a function'. Does anyone know how to properly do this?

Node.js code

router.get('/getSubViews', function(req, res) {

async.parallel([
    getViewers('quests'),
    getViewers('tips & tricks'),
    getViewers('general'),
    getViewers('cities')
], function(err, result) {
    if (err) {
        return res.status(500).json({
            message: "Something went wrong",
            err: err
        });
    }
    res.status(200).json({
        message: "Successfully retrieved the section",
        obj: 'whatever'
    });
});

function getViewers(subForum, callback){

        SubViewCount.findOne({'section': subForum}, function(err, doc){
            callback(null, doc.views);
        })
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313184 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO