Method description:
Test whether the file exists in a certain path.
The callback function contains an argument exists, true will exist, otherwise it will be false.
grammar:
The code copy is as follows:
fs.exists(path, callback)
Since this method belongs to the FS module, it is necessary to introduce the FS module before use (var fs= require("fs") )
Receive parameters:
path The file path to be detected
callback callback
example:
The code copy is as follows:
fs.exists('/etc/passwd', function (exists) {
util.debug(exists ? "it's there" : "no passwd!");
});
Source code:
The code copy is as follows:
fs.exists = function(path, callback) {
if (!nullCheck(path, cb)) return;
binding.stat(pathModule._makeLong(path), cb);
function cb(err, stats) {
if (callback) callback(err ? false : true);
}
};