Method description:
Create file directories asynchronously. If the directory already exists, an exception will be thrown.
grammar:
The code copy is as follows:
fs.mkdir(path, [mode], [callback(err)])
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 directory path to be created
mode directory permissions (read and write permissions), default 0777
callback callback, passing exception parameter err
example:
The code copy is as follows:
var fs = require('fs');
fs.mkdir('creatdir', 0777, function(err){
if(err){
console.log(err);
}else{
console.log("creat done!");
}
})
Source code:
The code copy is as follows:
fs.mkdir = function(path, mode, callback) {
if (util.isFunction(mode)) callback = mode;
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
binding.mkdir(pathModule._makeLong(path),
modeNum(mode, 511 /*=0777*/),
callback);
};