DEV Community

Katie
Katie

Posted on • Originally published at katiekodes.com on

Clean up old node_modules in Windows 10

Deleting old node_modules folders is the new defragging.

My computer was running slowly and I realized it was down to 8GB of disk space. I spent a lot of 2020 playing with Node.js-based static site generators. Each sample web site I created ended up with its own node_js subfolder containing lots and lots of code from the internet.

To get rid of it all, in Windows Explorer, I opened up C:\example\all_my_projects\ and typed name:node_modules type:(file folder) into the search box in the upper right corner and pressed Enter.

Screenshot of Windows Explorer search results

I then selected them all and deleted them all. I can rebuild them by running a command-line command of npm install within the folders where they used to live.

Sometimes, I’d get an Item Not Found error saying This is no longer located in C:\example\all_my_projects\project1\ Verify the item's location and try again.

In that case, I’d click the “Do this for all current items” box and click Skip.

To verify that they were all gone when Windows finally finished deleting them (over 5 minutes!), since the search results window still showed them in place, I hit Alt+(back arrow) and Alt+(forward arrow) a few times, trying to get the search results to refresh. (They also seemed to eventually refresh live without doing this.)

Windows indexes files for faster searching, so I belive it took Windows a little while to realize that the folders were gone and should no longer be in the search results.

I now have 9.5GB of disk space. No magic bullet, so I’ll need to look for other deletable things, but every GB counts on a small drive.

Top comments (0)