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.
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
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.
Directory created successfully!