0

I am fairly new in using javascript. I just want to write values in json file but could not do so. Second for loop run out while fs.readFileSync is getting data. Do I need callback for that and How it should be written. Here is my code :

for (i = 0; i < details.waypoints.length; i++) {
    if (details.waypoints[i].ts.getTime() - start_time.ts.getTime() > 115000) {
        for (j = 0; j < i; j++) {
            fs.readFile(Path.join(__dirname) + '/Modified_Data.json', 'utf8', function readFileCallback(err, data) {
                if (err) {
                    console.log(err);
                } else {
                    obj.table.push({
                       PathId: start_index,
                    }); //add some data
                    json = JSON.stringify(obj); //convert it back to json
                    fs.writeFile('Modified_Data.json', json, 'utf8', callback); // write it back
                }
            });

        }

    }

}
Developer
  • 255
  • 5
  • 18

0 Answers0