- Published on
How to remove recursively `node_modules` folders
- Authors
- Name
- Arnaud Ferrand

Photo by Andrea De Santis on Unsplash
node_modules
folders
How to remove recursively Have you ever found yourself running out of disk space, only to discover that the node_modules
folder in your projects is taking up a significant chunk of your storage? This is a common occurrence for developers working with Node.js applications, as these folders can quickly become bloated due to the dependencies and nested dependencies that they contain.

Image Source Reddit
There are several effective ways to clean up your node_modules folder recursively. While preparing this post, I discovered that npm
, yarn
, and company have prune
and cache
commands. I let you check this out, as we want a recursive cleanup here.
First, run this find command to verify the folders to be deleted visually:
find . -type d -name node_modules -prune
Then, run this to delete them all:
find . -type d -name node_modules -prune -exec rm -rf {} \;
That is all folks