node_modules
are the closet of your developer life. And just like that closet, it's packed to the brim with things you might never use again. Ever wondered how much digital real estate they're hogging?
Let's find out.
Visualizing the clutter
Pro Tip: Make sure you're in the right neighborhood.
cd
into the directory where most of your projects live, likedocuments
ordocuments/github
.
For the Mac and Linux folks
Want to know how much space you're dealing with? This command has got you covered:
cd documents
find . -name "node_modules" -type d -prune | xargs du -chs
Example output
255M ./Github/Trilon.io/node_modules
482M ./Github/Some_Demo/node_modules
707M total
If you like Nodejs, see our GitHub
If you're on Windows
Run this baby right here:
cd documents
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"
This will show you the plethora of node_modules
you’ve been collecting. A digital hoarder’s dream!
Join the conversation about open source in React, explore WebCrumbs
Time to take out the trash
Heads up: Don't just pull the trigger. Double-check your aim by running the above scripts to know exactly what you're about to delete.
For the Mac and Linux crew
Execute this to wipe node_modules
off the face of your drive:
cd documents
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
Want to be a part of our community? Dive into code
And for the Windows warriors
cd documents
FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"
Join our open-source movement and become a maker
The afterparty
I usually free up about 40-60GB doing this. Your results may vary, but hey, free space is free space!
Wrapping it up
- Check before you wreck — list all
node_modules
first. - Proceed with caution; this operation's got no Ctrl-Z.
- Remember to run
npm install
on projects you'll be revisiting.
And there you have it. You just decluttered your digital world.
Follow me for more tips.