fs open or create file code example
Example 1: node open file
const fs = require("fs");
// __dirname means relative to script. Use "./data.txt" if you want it relative to execution path.
fs.readFile(__dirname + "/data.txt", (error, data) => {
if(error) {
throw error;
}
console.log(data.toString());
});
Example 2: fs create or edit file
//Edit file or creates if doesnt exist
const fs = require('fs');
fs.appendFile(‘<fileName>’,<content>,callbackFunction)