I want a quickly dump objects into an external json file every time a form is submitted. However, using fs.writeFile only overwrites the one object rather than adding a new object.
How do I add a new object to the external file?
Object (JSON.stringify)
{"salary":"6000","poops":"6","time":"5","toCost":"$1.44"}
JS
fs.writeFile('data.json', JSON.stringify(data), function (err) {
if (err) throw err;
console.log('It\'s saved!');
fs.writeFile only overwrites the one object rather than adding a new object=> you don't have the choice. If you want, you can handle yourself several .json in order to group objects, and only update the groups you need to.