How to check if a file exists in Node.js? How to check this asynchronously?
Use fs.access(path, mode, callback) or fs.stat(path,callback) or fs.lstat(path, callback)
However it is not recommended to do such a check before read/write or any operation on the file because it may cause a race condition. In such a case do the error handling within fs.open() or fs.readFile() or fs.writeFile()