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

How to create an empty directory in nodejs

青灯夜游
Release: 2021-11-10 11:36:28
Original
2346 people have browsed it

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)])
Copy after login

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!");
 }
})
Copy after login

【 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template