DEV Community

CallmeHongmaybe
CallmeHongmaybe

Posted on

Removing clunky node_modules folder with Terminal

TLDR - node_modules takes a good chunk of your disk space ( up to the tunes of 10s of GBs ) and given a set of commands I believe I'm able to turn the situation around.

Motivation for removing clunky node_modules

So, a little bit of backstory...I tried contributing to FreeCodeCamp's codebase, but the current macOS version I'm in doesn't allow me to upgrade node to the version I'd wanted. Therefore, to make the backup process as swiftly as possible, I decided to take the tedious work of removing storage space.

It took days of tedium to make sense why the disk space always seem to miscalculate system storage size. At one point it bloated to over 77 GB, and I scoured my computer drive for bulky folders.

Image description

Even after deleting a bunch of junk folders out, the figure still hovers at around 50 something GBs.

How I realized it's time to remove those clunky folders

Among all of those burdensome clusters of data, I just found just how cluttered npm storage has become. Turns out there are node_modules all over my projects folder. All of this contributed a whopping 3.38 GBs.

So I concentrated all archived projects into one folder called web projs & stuff, and then I did two things:

  • Remove package-lock.json, because those files are being contained inside node_modules
  • Then proceed with node_modules

find ./Desktop/"web projs & stuff" -type d -name "node_modules"

find ./Desktop/"web projs & stuff" -type f -name "package-lock.json"

!! -exec rm -rf '{}' +

After that it drops down to 1.52 GB.

Top comments (0)