fs.exists, fs.existsSync - why are they deprecated?

前端 未结 7 511
遥遥无期
遥遥无期 2021-01-07 20:06

I noticed that the official node documentation says something startling about fs.exists:

\"fs.exists() is an anachronism and exists only

7条回答
  •  走了就别回头了
    2021-01-07 20:15

    There is no need to use fs.stat(), because fs.existsSync() has not been deprecated.

    https://nodejs.org/api/fs.html#fs_fs_existssync_path

    fs.existsSync(path)

    Added in: v0.1.21 path | Synchronous version of fs.exists(). Returns true if the file exists, false otherwise.

    Note that fs.exists() is deprecated, but fs.existsSync() is not. (The callback >parameter to fs.exists() accepts parameters that are inconsistent with other >Node.js callbacks. fs.existsSync() does not use a callback.)

提交回复
热议问题