This line of code overwrites all previous data. Is there are way, or another function that allows me to add the data on a new line?
fs.writeFileSync(path.resolve(__dirname, 'quotes.json'), JSON.stringify(quotey));
CodePudding user response:
fs.appendFileSync()
will append your new content to the file. Documentation here.
To make it a line boundary, just make sure you also add the appropriate \n
to the data you are appending so it will be separated from the next one that is appended (this assumes previous content also ends in a \n
.
fs.appendFileSync(path.resolve(__dirname, 'quotes.json'), JSON.stringify(quotey) "\n");