nodejs uses the mkdir() method of the fs module to create an empty directory. This method will create a file directory asynchronously. If the directory already exists, an exception will be thrown; the syntax "fs.mkdir(path, [mode ], [callback(err)])".
The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, DELL G3 computer.
Nodejs creates an empty directory using the mkdir() method of the fs module.
Method description:
Create a file directory asynchronously. If the directory already exists, an exception will be thrown.
Syntax:
fs.mkdir(path, [mode], [callback(err)])
Note: Since this method belongs to the fs module, the fs module needs to be introduced 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, pass the exception parameter err
Example:
var fs = require('fs'); fs.mkdir('creatdir', 0777, function(err){ if(err){ console.log(err); }else{ console.log("creat done!"); } })
【 Recommended learning: "nodejs tutorial"】
The above is the detailed content of How to create an empty directory in nodejs. For more information, please follow other related articles on the PHP Chinese website!