function writeToFile() {
fs.open(filepath,'r',function(fileExists, file) {
if (fileExists) {
fs.writeFile( filepath, JSON.stringify(prodDetail), (err) => {
if (err) console.error(err)
console.log('Data written')
});
} else {
console.log("File already exists!");
}
});
}
fs.exists(filename, function(exists) {
if(exists) {
// Create a file
}
else {
console.log("Deny overwrite existing", filename);
}
});