nodejs write file from buffer code example
Example 1: 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();
Example 2: write buffer to file in node
fs = require('fs');
fs.writeFile('helloworld.txt', 'Hello World!', function (err) {
if (err) return console.log(err);
console.log('Hello World > helloworld.txt');
});