Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道存在在 fs 中已弃用,但在 fs-extra 中可以。
我同时使用了 fsExtra.pathExists 和 fsExtra.exists。
但我找不到区别。
他们表现相同。
这两种方法没有太大区别。
fs-extra是 的超集fs,继承其所有方法,因此fsExtra.exists与 相同fs.exists。正如你所说,它已被弃用。
fs-extra
fs
fsExtra.exists
fs.exists
exists()和之间的区别pathExists()在于函数的签名。
exists()
pathExists()
与 fs.exists 类似,但具有正常的回调签名(错误,存在)。
在内部,fs本机模块使用 try catch 块,同时fs-extra使用 Promise 样式。他们都使用fs.access()方法来确定指定的文件是否可访问。
fs.access()
是的,它们都有相同的用途。