My current code for accessing my Firebase databse from Node.js looks roughly like this.:
var DesiredValue = "#";
ref.child("Example").once("value", function(snapshot) {
DesiredValue = snapshot.val();
console.log(DesiredValue)
});
console.log(DesiredValue)
It returns
>42
>#
where 42 is the value I want to grab, but I can't figure out how to retrieve it outside the scope of ref.child.(). I have tried the following which doesn't work.
var DesiredValue = ref.child("Example").once("value", function(snapshot) {
var DesiredValue = snapshot.val();
console.log(DesiredValue)
return DesiredValue
});
console.log(DesiredValue)
All I want to do is use 42 in the remainder of the code. Based on what I have read there might be some way of using JavaScript's 'this' to achieve my goal, but I am worried of messing with global variables and think there must be an easier way?