router.get('/xyz', function(req, res, next) {
  var myObj;
  XX.getXXByUsername("ee", function(err, doc){
    console.log("A: " + doc); //executes second, doc is object that I want
    myObj = doc; 
  });
  console.log("B: "+ " " + myObj); //executes first, myObj = undefined
  res.render("pr", {title: "XX", myObj: myObj});
});
Basicly, I am doing this because I want to send object to the jade template. I can get object in the A console, but in the B console myObj is undefined. I guess that it is because B console is executed before getXXbyUsername because in getXXbyUsername callback I define myObj.
I dont know if I explained what my problem is, but I am begginer and this is best explanation of problem that I can give.
 
     
    