Skip to content

Commit 14e2d67

Browse files
dfabulichFishrock123
authored andcommitted
fs,doc: undeprecate existsSync
This has been dragged through various long discussions and has been elevated to the CTC multiple times. As noted in #7455 (comment), while this API is still generally considered an anti-pattern, there are still use-cases it is best suited for, such as checking if a git rebase is in progress by looking if ".git/rebase-apply/rebasing" exists. The general consensus is to undeprecate just the sync version, given that the async version still has the "arguments order inconsistency" problem. The consensus at the two last CTC meetings this came up at was also to undeprecate existsSync() but keep exists() deprecated. See: #8242 & #8330 (Description write-up by @Fishrock123) Fixes: #1592 Refs: #4217 Refs: #7455 PR-URL: #8364 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 93c4874 commit 14e2d67

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

doc/api/fs.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,12 @@ fs.exists('/etc/passwd', (exists) => {
693693
});
694694
```
695695

696+
**Note that the parameter to this callback is not consistent with other
697+
Node.js callbacks.** Normally, the first parameter to a Node.js callback is
698+
an `err` parameter, optionally followed by other parameters. The
699+
`fs.exists()` callback has only one boolean parameter. This is one reason
700+
`fs.access()` is recommended instead of `fs.exists()`.
701+
696702
Using `fs.exists()` to check for the existence of a file before calling
697703
`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended. Doing
698704
so introduces a race condition, since other processes may change the file's
@@ -774,17 +780,18 @@ process.
774780
## fs.existsSync(path)
775781
<!-- YAML
776782
added: v0.1.21
777-
deprecated: v1.0.0
778783
-->
779784

780-
> Stability: 0 - Deprecated: Use [`fs.statSync()`][] or [`fs.accessSync()`][]
781-
> instead.
782-
783785
* `path` {String | Buffer}
784786

785787
Synchronous version of [`fs.exists()`][].
786788
Returns `true` if the file exists, `false` otherwise.
787789

790+
Note that `fs.exists()` is deprecated, but `fs.existsSync()` is not.
791+
(The `callback` parameter to `fs.exists()` accepts parameters that are
792+
inconsistent with other Node.js callbacks. `fs.existsSync()` does not use
793+
a callback.)
794+
788795
## fs.fchmod(fd, mode, callback)
789796
<!-- YAML
790797
added: v0.4.7
@@ -2167,7 +2174,6 @@ The following constants are meant for use with the [`fs.Stats`][] object's
21672174
[`Buffer`]: buffer.html#buffer_buffer
21682175
[Caveats]: #fs_caveats
21692176
[`fs.access()`]: #fs_fs_access_path_mode_callback
2170-
[`fs.accessSync()`]: #fs_fs_accesssync_path_mode
21712177
[`fs.appendFile()`]: fs.html#fs_fs_appendfile_file_data_options_callback
21722178
[`fs.exists()`]: fs.html#fs_fs_exists_path_callback
21732179
[`fs.fstat()`]: #fs_fs_fstat_fd_callback
@@ -2180,7 +2186,6 @@ The following constants are meant for use with the [`fs.Stats`][] object's
21802186
[`fs.readFile`]: #fs_fs_readfile_file_options_callback
21812187
[`fs.stat()`]: #fs_fs_stat_path_callback
21822188
[`fs.Stats`]: #fs_class_fs_stats
2183-
[`fs.statSync()`]: #fs_fs_statsync_path
21842189
[`fs.utimes()`]: #fs_fs_futimes_fd_atime_mtime_callback
21852190
[`fs.watch()`]: #fs_fs_watch_filename_options_listener
21862191
[`fs.write()`]: #fs_fs_write_fd_buffer_offset_length_position_callback

0 commit comments

Comments
 (0)