node js create file if not exists code example
Example 1: nodejs fs create file if not exists
fs.exists(filename, function(exists) {
if(exists) {
// Create a file
}
else {
console.log("Deny overwrite existing", filename);
}
});
Example 2: fs create or edit file
//Edit file or creates if doesnt exist
const fs = require('fs');
fs.appendFile(‘<fileName>’,<content>,callbackFunction)