Instructions for the fs.mkdir method in node.js

  • 2020-05-05 10:56:30
  • OfStack

method description:

Create the file directory asynchronously. If the directory already exists, an exception is thrown.

syntax:


fs.mkdir(path, [mode], [callback(err)])

Since this method belongs to the fs module, it is necessary to introduce the fs module (var fs= require(" fs "))

before using it

receive parameters:

path                   will create the directory path

mode                   directory permissions (read and write permissions), default 0777

The callback           callback passes the exception parameter err

Example of :


var fs = require('fs');
fs.mkdir('creatdir', 0777, function(err){
 if(err){
  console.log(err);
 }else{
  console.log("creat done!");
 }
})

source code:


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);
};


Related articles: