GeezerVison is showing github.com — doc: clarify that fs.exists() may return false for existing symlink · nodejs/node@c6166cd
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 |
|---|
@@ -2736,7 +2736,7 @@ changes: |
2736 | 2736 | * `callback` {Function} |
2737 | 2737 | * `exists` {boolean} |
2738 | 2738 |
|
2739 | | -Test whether or not the given path exists by checking with the file system. |
| 2739 | +Test whether or not the element at the given `path` exists by checking with the file system. |
2740 | 2740 | Then call the `callback` argument with either true or false: |
2741 | 2741 |
|
2742 | 2742 | ```mjs |
@@ -2753,6 +2753,9 @@ parameter, optionally followed by other parameters. The `fs.exists()` callback |
2753 | 2753 | has only one boolean parameter. This is one reason `fs.access()` is recommended |
2754 | 2754 | instead of `fs.exists()`. |
2755 | 2755 |
|
| 2756 | +If `path` is a symbolic link, it is followed. Thus, if `path` exists but points |
| 2757 | +to a non-existent element, the callback will receive the value `false`. |
| 2758 | +
|
2756 | 2759 | Using `fs.exists()` to check for the existence of a file before calling |
2757 | 2760 | `fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended. Doing |
2758 | 2761 | so introduces a race condition, since other processes may change the file's |
|