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.
Syntax:
javascript
Output:
fsPromises.mkdir(path, options)Parameters: This method accept two parameters as mentioned above and described below:
- path: This parameter is a String, Buffer or URL and holds the path of the directory has to be created.
- 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
Example:
// 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!