GeezerVison is showing github.com — doc: clarify that fs.exists() may return false for existing symlink · nodejs/node@73860ac
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/fs.md +4-1Lines changed: 4 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2656,7 +2656,7 @@ changes: |
2656 | 2656 | * `callback` {Function} |
2657 | 2657 | * `exists` {boolean} |
2658 | 2658 |
|
2659 | | -Test whether or not the given path exists by checking with the file system. |
| 2659 | +Test whether or not the element at the given `path` exists by checking with the file system. |
2660 | 2660 | Then call the `callback` argument with either true or false: |
2661 | 2661 |
|
2662 | 2662 | ```mjs |
@@ -2673,6 +2673,9 @@ parameter, optionally followed by other parameters. The `fs.exists()` callback |
2673 | 2673 | has only one boolean parameter. This is one reason `fs.access()` is recommended |
2674 | 2674 | instead of `fs.exists()`. |
2675 | 2675 |
|
| 2676 | +If `path` is a symbolic link, it is followed. Thus, if `path` exists but points |
| 2677 | +to a non-existent element, the callback will receive the value `false`. |
| 2678 | +
|
2676 | 2679 | Using `fs.exists()` to check for the existence of a file before calling |
2677 | 2680 | `fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended. Doing |
2678 | 2681 | so introduces a race condition, since other processes may change the file's |
|