Home  >  Article  >  Web Front-end  >  How to create an empty directory in nodejs

How to create an empty directory in nodejs

青灯夜游
青灯夜游Original
2021-11-10 11:36:282240browse

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)])".

How to create an empty directory in nodejs

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn