To delete a directory in Node.js, we can use the built-in fs module that provides a rmdir() method. The rmdir() method removes the specified directory by path.
Here is an example code that shows how to delete a directory using Node.js:
index.tsx316 chars11 linesIn the above code, we use the rmdir() method to delete the directoryPath. The { recursive: true } options delete the directory recursively, including all files and subdirectories. If an error occurs, we display an error message. Otherwise, we display a success message.
gistlibby LogSnag