- Open the directory on your computer where all your
node_modules
will be found (justcd
into it from the command line) - Run this line while within the above directory to see a list of all the node modules that it contains (along with how much space theyโre taking up):
find . -name "node_modules" -type d -prune | xargs du -chs
- Double check that nothing in the resulting list is a surprise (for me, none of them came from folders where I hadnโt created a Node project, which is exactly what I expected); also check to see how much total space they take up (it tells you at the bottom of the list; for me, it was 9.4 GB)
- Run this line to actually delete all the modules:
find . -name "node_modules" -type d -prune | xargs du -chs
- It will take a long time for the above line to execute (for me, I think it took about 10 minutes); after, check your computerโs storage (for me, sure enough, I gained about 10 GB of free space)
- If you ever want to reinstall node modules for any repo (e.g., for an old project that you want to spruce up), just go to its folder and run
npm i
to reinstall all its dependencies (aka, node modules)
h/t Mark Pieszak
Top comments (0)