doc: update description of fs.exists in fs.markdown
authorJames M Snell <jasnell@gmail.com>
Fri, 14 Aug 2015 17:59:07 +0000 (10:59 -0700)
committerJames M Snell <jasnell@gmail.com>
Wed, 26 Aug 2015 01:51:57 +0000 (18:51 -0700)
per: https://github.com/joyent/node/pull/7944

originally submitted by @oconnore

Minor update to the description in `fs.exists()`

Reviewed By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/2378

doc/api/fs.markdown

index c0f72c59c641012bd3d085013b95b15e6988dc69..ac40eeb014b235c0de3c8cbbc7055f88fbc9a993 100644 (file)
@@ -680,15 +680,11 @@ Then call the `callback` argument with either true or false.  Example:
       console.log(exists ? "it's there" : 'no passwd!');
     });
 
-`fs.exists()` is an anachronism and exists only for historical reasons.
-There should almost never be a reason to use it in your own code.
-
-In particular, checking if a file exists before opening it is an anti-pattern
-that leaves you vulnerable to race conditions: another process may remove the
-file between the calls to `fs.exists()` and `fs.open()`.  Just open the file
-and handle the error when it's not there.
-
-
+`fs.exists()` should not be used to check if a file exists before calling
+`fs.open()`. Doing so introduces a race condition since other processes may
+change the file's state between the two calls. Instead, user code should
+call `fs.open()` directly and handle the error raised if the file is
+non-existent.
 
 ## fs.existsSync(path)