Instructions for the fs.readdir method in node.js
- 2020-05-05 10:56:02
- OfStack
method description:
The file directory is read asynchronously.
syntax:
fs.readdir(path, [callback(err,files)])
Since this method belongs to the fs module, it is necessary to introduce the fs module (var fs= require(" fs "))
before using itreceive parameters:
path directory path
callback callback, passing two parameters err and files. files is an array containing the names of all files in the specified directory.
Example of :
var fs = require('fs');
fs.readdir('readdirtest', function(err,files){
if(err){
console.log(err);
}
console.log(files);
})
source code:
fs.readdir = function(path, callback) {
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
binding.readdir(pathModule._makeLong(path), callback);
};