Hi!
I didn't run this code, but maybe is a solution
router.get('/account',isAuthenticated, function(req,res){
var following_users_details = [];
var i = 0;
getOneUser();
function getOneUser() {
var following_user = req.user.following_users[i++];
if (!following_user) {
res.render('users/userAccount',{user:req.user, following_users_details:following_users_details });
return;
}
User.findOne({'username' : following_user },
function(err,user)
{
if (!err)
following_users_details.push({
username: user.username,
profilepic : user.photo,
userbio : user.bio
});
setTimeout(getOneUser, 0);
});
}
});
The original code returned a result BEFORE the find one user executes the callback.
The above code retrieves one user, and then, in the callback, invoke the same function to retrieve another user. It should be better solutions, but I hope this code works.
Understanding callbacks/async is the price to pay to live at Node.js paradise ;-)
Angel "Java" Lopez
@ajlopez