This article mainly introduces node. fs. exists method usage instructions. This article introduces fs. exists method description, syntax, receive parameters, use instances, and implement Source Code. For more information, see
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:
The 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:
The Code is as follows:
Fs. exists ('/etc/passwd', function (exists ){
Util. debug (exists? "It's there": "no passwd! ");
});
Source code:
The 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 );
}
};