The fs exists method in the file system module of nodejs should not be used at all these days. In node 8.x it has been deprecated, and it is reasonable that it might not work at all in future versions of nodejs. So then how does one test if a file is there or not, well there are a number of ways to do that by just opening the file, and then handle the error in the event that the file is not there.In all fairness that is how it should be done anyway using the fs exists method just makes things more complicated than they need to be.
Open way to go about kicking fs exists to the curb is to just use fs open with the right flags. There are many options when it comes to flags that can be used with fs open, but for this example the two flags that are of interest are the r+ and w+ flags. The r+ flag will open a file for reading and writing, but will throw an error in the event that the file is not there, in addition it will not create the file as well. The w+ flag on the other hand will do the same thing only it will not throw and error in the event that the file is not there, and will create it, or just open it if it is there.
So a simple method that returns a promise can be written like this.
Keep in mode that I was using nodejs 8.x when I wrote this, in later versions of nodejs the fs.open method itself might return a promise.
So then the fs open method could be used to throw and error in the event that a file is not there, then something can be done such as calling the fs open method again but with the w+ flag then continue g on like normal.
To make things even more simple why not just use the w+ flag by itself even.