I am trying to read a file and I want that logic to be inside a function, I did - that is below, I see I should get the result in terms of promise object, but I am not sure, the below code output undefined
. Please tell how to fix this one ?
var fs = require('fs');
function readAppData() {
var content;
fs.readFile('app-lock.json', function read(err, data) {
if (err) { console.log(err); }
try {
content = JSON.parse(data);
} catch (err) {
console.log(err);
}
}).then(t => {return content});
}
console.log(readAppData())