So I have this code:
http://pastebin.com/42aHz5fy (sorry,I failed at using <pre>
tags in StackOverflow editor)
The console.log() inside getStats function returns an object,but in the second console.log()(outside the function,after calling it),it returns "undefined".
And this is my console:
https://i.stack.imgur.com/aU465.png
Why is it returning undefined?
var getStats = function (){
fs.readFile('Documents/GitHub/kag-gather-irc-bot/stats.json', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
everyStats = JSON.parse(data);
console.log(everyStats);
return everyStats;
});
}
STATS = getStats();
console.log(STATS);