DEV Community


Delete all node_modules from your machine and save space

Love helping people and MPB.
・1 min read

Couple of months ago I has having disk space problems on my development machine and started to look for unused folders that were taking some space. Looking for solutions on the internet, I've found that local node_moduless take a lot of space when you have a couple of Javascript projects. Then, I started looking for solutions on how to smartly delete these folders, since I can rebuild them with yarn if I need.

Just FYI, a raw npx create-react-app folder has a 227mb node_modules.

So, let's go to the recipe. I present you two ways of deleting these folders:

  • npx npkill will spawn an interactive interface for you to select the node_modules you want to delete.
  • find . -name 'node_modules' -type d -prune -exec rm -rf '{}' + will find and delete every node_modules folder under the current directory, so beware where you're running it.

If you want more options, check this SOF question.

Discussion (5)

binyamin profile image
Binyamin Green

yarn has a new system (plug n play) where there are no node_modules!

lucis profile image
Lucis Author

Yeah, Yarn 2 was a very cool release!

I'm still a bit afraid of migrating my projects to use it. One cool thing about yarn vs npm in the past was that it was almost seamless what you had to in your project...

lucis profile image
Lucis Author

When I've first run this, I lost more than 13GB haha

So many angularjs projects...