From 7e1573170030b25e69fc079a6c5e919df2d96d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 26 Jun 2024 11:38:30 +0200 Subject: [PATCH] doc: clarify that fs.exists() may return false for existing symlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Moshe Atlow Reviewed-By: Yagiz Nizipli Reviewed-By: Marco Ippolito Reviewed-By: Luigi Pinca Reviewed-By: Ulises Gascón --- doc/api/fs.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 4bc59ae2e9eed2..6fe661900a6296 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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