fs.writeFile node.js code example
Example 1: nodejs readfile
const fs = require('fs');
fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
if (err) {
console.error(err);
return
}
console.log(data);
});
Example 2: writefile in node js
// append_file.js
const fs = require('fs');
// add a line to a lyric file, using appendFile
fs.appendFile('empirestate.txt', '\nRight there up on Broadway', (err) => {
if (err) throw err;
console.log('The lyrics were updated!');
});