1

I'm trying to design a webpage. I have a function that I call to get all info needed for an individual's home page. A snippet of the code is:

exports.getHomePageData = function(userId, cb) {
    var pageData = {};

    pageData.userFullName = dbUtil.findNameByUserId(userId, function(err){
        if (err) cb(err);
    });
    pageData.classes = dbUtil.findUserClassesByUserId(userId, function(err){
        if (err) cb(err);
    });

    cb(pageData);
}

The problem I'm having is that the cb(pageData) is being called before I even finish setting the elements.

I've seen that people use the async library to solve this, but I was wondering if there was any other way for me to do it without needing more modules.

4

2 に答える 2