Description of the fs. exists method in node. js, node. jsfs. exists
Method description:
Test whether a file in a path exists.
The callback function contains an exists parameter. If the value is true, the object exists. Otherwise, the value is false.
Syntax:
Copy codeThe Code is as follows:
Fs. exists (path, callback)
Because this method belongs to the fs module, we need to introduce the fs module (var fs = require ("fs") before use "))
Receiving parameters:
Path file path to be detected
Callback
Example:
Copy codeThe Code is as follows:
Fs. exists ('/etc/passwd', function (exists ){
Util. debug (exists? "It's there": "no passwd! ");
});
Source code:
Copy codeThe Code 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 );
}
};