File tree 1 file changed +5
-9
lines changed
1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -680,15 +680,11 @@ Then call the `callback` argument with either true or false. Example:
680
680
console.log(exists ? "it's there" : 'no passwd!');
681
681
});
682
682
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.
692
688
693
689
## fs.existsSync(path)
694
690
You can’t perform that action at this time.
0 commit comments