Categories
JavaScript Answers

How to delete a directory that is not empty with Node?

Spread the love

To delete a directory that is not empty with Node, we install rimraf.

To install it, we run

npm install rimraf

Then we write

rmdir = require("rimraf");
rmdir("some/directory/with/files", (error) => {});

to call rmdir to remove the some/directory/with/files folder.

If there’s any error, then we get the error from the callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *