Create a file if it doesn't already exist
I think the answer is:
Just open the file and handle the error when it's not there.
Try something like:
function createFile(filename) {
fs.open(filename,'r',function(err, fd){
if (err) {
fs.writeFile(filename, '', function(err) {
if(err) {
console.log(err);
}
console.log("The file was saved!");
});
} else {
console.log("The file exists!");
}
});
}
fs.closeSync(fs.openSync('/var/log/my.log', 'a'))