Skip to content

Commit 27c07b3

Browse files
jasnellrvagg
authored andcommittedAug 26, 2015
doc: update description of fs.exists in fs.markdown
per: nodejs/node-v0.x-archive#7944 originally submitted by @oconnore Minor update to the description in `fs.exists()` Reviewed By: Sakthipriyan Vairamani <[email protected]> PR-URL: #2378
1 parent 52018e7 commit 27c07b3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed
 

‎doc/api/fs.markdown

+5-9
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,11 @@ Then call the `callback` argument with either true or false. Example:
680680
console.log(exists ? "it's there" : 'no passwd!');
681681
});
682682

683-
`fs.exists()` is an anachronism and exists only for historical reasons.
684-
There should almost never be a reason to use it in your own code.
685-
686-
In particular, checking if a file exists before opening it is an anti-pattern
687-
that leaves you vulnerable to race conditions: another process may remove the
688-
file between the calls to `fs.exists()` and `fs.open()`. Just open the file
689-
and handle the error when it's not there.
690-
691-
683+
`fs.exists()` should not be used to check if a file exists before calling
684+
`fs.open()`. Doing so introduces a race condition since other processes may
685+
change the file's state between the two calls. Instead, user code should
686+
call `fs.open()` directly and handle the error raised if the file is
687+
non-existent.
692688

693689
## fs.existsSync(path)
694690

0 commit comments

Comments
 (0)
Please sign in to comment.