router.get('/getAllMeals',function(req,res){
var allMeals = [];
allMeals.push("foo");
mealsRef.on("value",function(dataSnapShot){
dataSnapShot.forEach(function(child){
console.log(child.val());
var oneMeal = child.val();
allMeals.push(oneMeal);
});
});
allMeals.forEach(function(obj){
console.log(obj);
});
res.send(allMeals);
}); //RETRIEVE ALL
In the above code, I cannot add oneMeal which is a valid JSON object to the allMeals array I created. The result of console.log only shows the "foo" and also the length is 1.
});?