Write stringified object to file.
npm i writejson --save To handle formating optional argument options could be used according to JSON.stringify.
Asynchonouse write stringified object.
const writejson = require('writejson'); const [error] = await tryToCatch(writejson, 'data.json', {hello: 'world'}); if (error) console.error(error.message); const options = { replacer: ['hello'], // properties to put in json space: 4, // default space count eof: true, // default new line at end of file encoding: 'utf8', // default mode: '0o666', // default flag: 'w', // default }; await writejson('data.json', {hello: 'world'}, options);Synchonouse write stringified object.
try { writejson.sync('data.json', {hello: 'world'}); } catch(error) { console.log(error.message); }Synchonouse try to write stringified object.
writejson.sync.try('data.json', {hello: 'world'});MIT