Search Results

Search found 1 results on 1 pages for 'user1995327'.

Page 1/1 | 1 

  • How to set variable before callback is called?

    - by user1995327
    I'm trying to design a webpage... I have a function that I call get all info needed for an idividuals home page. A snippet of the codes 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 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... Thanks!

    Read the article

1