nodejs saving in local file code example

Example 1: data not write in file node js

const fs = require('fs');

fs.readFile('file.txt', 'utf-8', (err, data) => {
    if(err) {
        throw err;
    }
    console.log(data);
});

Example 2: node js store values in file

var fs = require('fs');

var myOptions = {
  name: 'Avian',
  dessert: 'cake'
  flavor: 'chocolate',
  beverage: 'coffee'
};

var data = JSON.stringify(myOptions);

fs.writeFile('./config.json', data, function (err) {
  if (err) {
    console.log('There has been an error saving your configuration data.');
    console.log(err.message);
    return;
  }
  console.log('Configuration saved successfully.')
});