1const fs = require('fs');
2const fileName = './file.json';
3const file = require(fileName);
4
5file.key = "new value";
6
7fs.writeFile(fileName, JSON.stringify(file), function writeJSON(err) {
8 if (err) return console.log(err);
9 console.log(JSON.stringify(file));
10 console.log('writing to ' + fileName);
11});
12