Back to blog

Node_Modules Black Hole: Recursively Finding and Cleaning Projects

Kapil

Math check: A typical fresh React project is ~300MB. A Next.js project is ~800MB. If you do one tutorial a week, or start one side project a month... after 2 years, that is 50GB of disk space occupied by code you haven't touched since 2024.

The problem with node_modules isn't the size of one folder—it's the quantity of them.

The Finder Fail

If you try to use macOS Finder to "Calculate all sizes" of your ~/Projects folder, you will be waiting a long time. node_modules folders contain tens of thousands of tiny files. Finder hates this. It chokes on the I/O.

The Terminal Solution: find and rm

To find the worst offenders, you can use the find command.

List all node_modules folders sorted by depth:

find . -name "node_modules" -type d -prune

This works, but it's just a list. It doesn't tell you effectively which ones are safe to delete or how old they are.

The Nuclear Option: recursive delete

Warning: Do not run this unless you are absolutely sure you want to nuke every dependency cache in the directory.

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

This will force you to run npm install on every project you open again.

The DissectMac Approach: "Developer Filters"

We added a specific "Developer Filter" to DissectMac because we faced this exact problem.

Instead of scanning your whole drive, DissectMac can highlight "Nested Folders".

DissectMac Interface

  1. Scan your ~/Projects or ~/dev directory.
  2. Type node_modules in the filter bar.
  3. Instantly see specific node_modules folders sizing up against each other.
  4. Notice that old-hackathon-project is taking up 1.2GB?
  5. Right-click -> Move to Trash.

You keep the code (src/, package.json), but you lose the 50,000 dependency files. It's the perfect balance for archiving old work.

Don't Forget ~/.npm

NPM keeps its own local cache of tarballs. This can also grow to 10GB+.

npm cache verify

or for a full clean:

npm cache clean --force

Keep your code, delete your dependencies.

Visualize Your Project Folder with DissectMac →

Finding these files too slow?

DissectMac visualizes your entire drive, making it obvious where these hidden caches are hiding.

DissectMac Interface

Continue Reading