How to Delete ALL node_modules folders on your machine and Free up HD space!

Mark Pieszak
Aug 25, 2019 · 3 min read

Originally published on the Trilon Blog on Aug 7, 2019.

Dreaded “out of HD space” message on MAC

Whenever we work on a new project we need to run npm install, but how often do we think about the toll this takes on our hard-drive?

A single node_modules folder can take up anywhere from 200+ megabytes of space.

Now take a look at your github/ folder, or wherever else you're storing the majority of your projects, and you can start to see where some of your free hard-drive space has gone!

I recently tweeted about this, as it’s something I use every few months and wanted to share with others who might have ran into the same situation themselves!

List all node_modules found in a Directory:

First, let’s take a look at ALL the node_modules we have in a directory, before we actually start deleting them!

NOTE: Make sure you cd into a specific directory where most of your projects are. ie: documents or documents/github.

Mac / Linux:

This command will also show us how much space the folder is occupying as well!


This list will give you a good idea of just the sheer amount of projects you have installed on your machine!

Delete all node_modules found in a Directory:

NOTE: Use caution here, and make sure that you are in a directory where you’re comfortable removing all the instances of node_modules, run the script above to see a full list of them all before deleting.

This script is actually very similar to the one above, but we’re going to be utilizing rm -rf to completely delete them.

WARNING: This process is irreversible!

Mac / Linux:


There we have it!

For me personally, this typically clears out about 40–60GB from my hard-drive, but your mileage may vary!

In Conclusion

  • Make sure to list all node_modules in a given directory BEFORE deleting them.
  • Make sure to be cautious as this process is irreversible!
  • Remember to npm install on the projects you need to work on again.
  • Enjoy the free space! :)

Trilon — Next-level Application Consulting is a software consulting firm aimed to help get teams & applications up to speed by working with some of the leading industry experts in JavaScript, NodeJS, NestJS Framework & ASP.NET.

Contact us:


Trilon Consulting — Next-level Application Consulting

Originally published at on August 7, 2019.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store