append file node js code example
Example 1: How to append to a file in Node?
const fs = require('fs');
fs.appendFile('message.txt', 'data to append', function (err) {
if (err) throw err;
console.log('Saved!');
});
const fs = require('fs');
fs.appendFileSync('message.txt', 'data to append');
Example 2: writefile in node js
const fs = require('fs');
let writeStream = fs.createWriteStream('secret.txt');
writeStream.write('aef35ghhjdk74hja83ksnfjk888sfsf', 'base64');
writeStream.on('finish', () => {
console.log('wrote all data to file');
});
writeStream.end();