I'm an experienced web developer, software engineer, and leader. Welcome to my blog. If you need to reach out you can continue the conversation with a tweet to @geedew. I hope you find what you are looking for here. You can also find me on Github and StackOverflow.

Remove a directory that is not empty in NodeJS

A quick pro-tip for handling this situation.

NodeJS provides an easy to use fs.rmdir command that follows the POSIX standard. This unfortunately means that it will error ENOTEMPTY if there is any file in the directory you are attempting to remove. NodeJS doesn’t have an easy way to force the removal, so you have to get fancy.

By far, the easiest, safest and most cross environment approach is to use rimraf whose source code shows nearly 250 lines of premium quality work.

It’s 2018, use del.

Or if you must, try trash. It’s really neat too.

/ / / Read More