DEV Community

jastuccio
jastuccio

Posted on • Updated on • Originally published at astucc.io

Trash your unused node_modules folders and regain hard drive space

If you are like me and have a lot of legacy projects on your computer you should consider deleting your node modules folder. A few minutes and a terminal command gave me back several GB of hard drive space!

before:
Alt Text

after:
Alt Text

I also ran this in another folder and saved 700mb

  • Before getting started make sure your projects backed up to Github or some-place safe.
cd directory-where-your-projects-live

find . -name "node_modules" -type d -prune -exec trash -rf '{}' +
Enter fullscreen mode Exit fullscreen mode

You can npm install dependencies to add them back to any projects where you need them.

  • If you don't have trash installed (and you probably should) use rm instead like this:

find . -name "node_modules" -type d -prune -exec rm -rf '{}' +

sources:
https://rtmccormick.com/2018/01/10/clear-node-modules-folders-recursively-mac-linux/

Top comments (0)