async file read node js
function firstFunction(_callback) {
// do some asynchronous work
// and when the asynchronous stuff is complete
const fs = require('fs');
let jsonData;
fs.readFile("industriesByCat.txt", 'utf8', function (err, data) {
if (err) throw err;
jsonData = JSON.parse(data);
console.log(jsonData);
//This is important for callback
_callback();
});
}
function secondFunction() {
// call first function and pass in a callback function which
// first function runs when it has completed
firstFunction(function () {
console.log('huzzah, I\'m done!');
});
}
secondFunction();