Answers for "async file read node js"

0

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();
Posted by: Guest on September-10-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language