![]() |
VOOZH | about |
The fsPromises.rmdir() method is used to delete a directory at the given path. It can also be used recursively to remove nested directories. It resolves the Promise with no arguments upon success.
Syntax:
fsPromises.rmdir( path, options )
Parameters: This method accept two parameters as mentioned above and described below:
Below examples illustrate the fsPromises.rmdir() method in Node.js:
*Create "gfg_directory" in the machine path to run the code properly.
Example 1: This example uses fsPromises.rmdir() method to delete a directory.
Filename: index.js
Output:
Current filenames: gfg_directory index.js package.json Folder Deleted! Current filenames: index.js package.json
Example 2: This example uses fsPromsies.rmdir() method with the recursive parameter to delete nested directories.
Output:
Current filenames:
gfg_directory
index.js
package.json
[Error: ENOTEMPTY: directory not empty,
rmdir 'F:\tutorials\nodejs-fs-rmdir\directory_one'] {
errno: -4051,
code: 'ENOTEMPTY',
syscall: 'rmdir',
path: 'F:\\tutorials\\nodejs-fs-rmdir\\directory_one'
}
Recursive: Directories Deleted!
Current filenames:
index.js
package.json
Reference: https://nodejs.org/api/fs.html#fs_fspromises_rmdir_path_options