doc: clarify that fs.exists() may return false for existing symlink

Given that this API is problematic in any case, we should be precise
about its (perhaps surprising) behavior.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Tobias Nießen 2024-06-26 11:38:30 +02:00 committed by GitHub
parent ab5e58bf29
commit feaa0c7088
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2736,7 +2736,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
@ -2753,6 +2753,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