Skip to content

Commit

Permalink
doc: clarify that fs.exists() may return false for existing symlink
Browse files Browse the repository at this point in the history
Given that this API is problematic in any case, we should be precise
about its (perhaps surprising) behavior.

PR-URL: #53566
Reviewed-By: Jithil P Ponnan <jithil@outlook.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
  • Loading branch information
tniessen authored and marco-ippolito committed Aug 19, 2024
1 parent bcd08be commit 73860ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,7 @@ changes:
* `callback` {Function}
* `exists` {boolean}
Test whether or not the given path exists by checking with the file system.
Test whether or not the element at the given `path` exists by checking with the file system.
Then call the `callback` argument with either true or false:
```mjs
Expand All @@ -2673,6 +2673,9 @@ parameter, optionally followed by other parameters. The `fs.exists()` callback
has only one boolean parameter. This is one reason `fs.access()` is recommended
instead of `fs.exists()`.
If `path` is a symbolic link, it is followed. Thus, if `path` exists but points
to a non-existent element, the callback will receive the value `false`.
Using `fs.exists()` to check for the existence of a file before calling
`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended. Doing
so introduces a race condition, since other processes may change the file's
Expand Down

0 comments on commit 73860ac

Please sign in to comment.