Skip to content
Related Articles

Related Articles

Node.js | fsPromises.mkdir() Method
  • Last Updated : 11 Jun, 2020

The fsPromises.mkdir() method is used to asynchronously create a directory then resolves the Promise with either no arguments, or the first directory path created if recursive is true.


fsPromises.mkdir(path, options)

Parameters: This method accept two parameters as mentioned above and described below:

  1. path: This parameter is a String, Buffer or URL and holds the path of the directory has to be created.
  2. options: It is an Object or an Integer
    • recursive: This parameter holds the recursive boolean value. By default it is false.
    • mode: The mode option is used to set the directory permission, by default it is 0777. It is a String or an Integer

Return Value: It returns the Promise object which represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.

Below example illustrates the use of fsPromises.mkdir() method in Node.js.


// Node.js program to demonstrate 
// the fsPromises.mkdir() Method 
// Include fs and path module 
const fs = require('fs');
const fsPromises = fs.promises;
fsPromises.mkdir('fs_test2').then(function() {
    console.log('Directory created successfully');
}).catch(function() {
    console.log('failed to create directory');


Directory created successfully!
My Personal Notes arrow_drop_up
Recommended Articles
Page :