fs.writeFile(filename,data,{flag: "wx"},function(err){
if(err) throw err
console.log('Date written to file, ',filename)
})
As you can see in the above code snippet, the third parameter is the parameter / flag. There are optional and used to indicate the behavior of the file to be opened.
I passed "wx" as an option, which indicates that the file will be open for writing and will be created if it does not exist. But he will fail if he already exists.
By default, "w" is passed as an option.
For further reading of various options here
source
share