I use the following code and the code is not getting to the if statement
function getContent(key) {
var filePath = path.join(__dirname, '../test.txt');
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
....
var fileKeyValObj = {};
return fileKeyValObj[key];
});
}
I was able to access to the return of the previous method via debug and its working ok... Here the function is not getting to the if
getContent('web', function (cmd) {
if (typeof cmd !== 'undefined') {
Here the key is the web which I sent and I see that the return of the getContent is with the right value.
I see this post but I think that I did the same ,do I miss something here? How do I return the response from an asynchronous call?
Btw in this case its recommended to use promise??? like blue bird