node.js fs.exists() will be deprecated, what to use instead?

后端 未结 4 801
我在风中等你
我在风中等你 2021-02-18 13:05

According to the documentation node.js fs.exists() will be deprecated. Their reasoning:

fs.exists() is an anachronism and exists only for historical reasons.

4条回答
  •  日久生厌
    2021-02-18 13:44

    Use fs.existsSync().

    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.)

提交回复
热议问题