fs.exists方法在node.js中不再存在

Enr*_*ent 5 node.js

我使用节点v0.6.12

这是我的代码:

var fs = require("fs");

fs.exists(".", function() {
    console.log("Whatever);
});
Run Code Online (Sandbox Code Playgroud)

我得到这个输出:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Object #<Object> has no method 'exists'
    at Object.<anonymous> (/home/dbugger/Projects/nodetest/test.js:3:4)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:32)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:41)
Run Code Online (Sandbox Code Playgroud)

"存在"已被弃用吗?那我可以用什么?

bro*_*ofa 6

您可以使用,path.exists()但在最新版本的节点中不推荐使用它.fs.exists()这些天是首选的api ,所以你需要准备好在某个时候切换.

$ node --version
v0.8.3

$ node
> require('fs').exists
[Function]
> require('path').exists
[Function: deprecated]
Run Code Online (Sandbox Code Playgroud)

相关文档: