Back to blog

You Probably Have 50GB of node_modules You Forgot About

Kapil

The node_modules folder is a meme for a reason. A simple React app can have 800MB of dependencies. A Next.js project? Easily 1GB+.

Now multiply that by every tutorial you followed, every side project you abandoned, every "let me just try this framework" experiment. If you've been doing web development for more than a year, you probably have a lot of node_modules scattered across your drive.

Here's how we clean them up.

Step 1: See the Damage

To find all node_modules folders and see which ones are biggest, you can run:

find ~ -name "node_modules" -type d -prune 2>/dev/null | head -20

This lists node_modules folders in your home directory. For size information, you'd check each folder individually or use a visual tool.

Step 2: The npm Cache

Before touching individual projects, consider clearing the global npm cache:

npm cache clean --force

This removes downloaded package tarballs that npm keeps around. It can free up a few GB depending on how long you've been doing Node development.

Running npm install in a project will just re-download what it needs.

Step 3: Mass Delete with npkill

The best tool for finding and deleting node_modules folders is npkill:

npx npkill

It finds every node_modules folder on your system and lets you interactively delete them. Use arrow keys to scroll, Space to delete. It shows folder sizes so you can prioritize.

Note: This will find ALL node_modules, including projects you're actively working on. You'll need to run npm install or yarn to restore dependencies for any project you want to use again.

Visual Approach

When using DissectMac, node_modules folders show up as dense clusters of small files. If you see a large block under a project folder you haven't touched in months, that's a good candidate for cleanup.

DissectMac Interface

You can right-click, reveal in Finder, and decide whether to delete the whole project or just the node_modules folder.

Don't Forget These Other Offenders

While cleaning up Node stuff, also check:

  • ~/.npm – npm's global cache and logs
  • ~/.nvm/versions – if you use nvm, you might have multiple Node versions installed
  • ~/.yarn/cache – Yarn's global cache

The "Active Project" Rule

We only keep node_modules for projects we've touched in the last 30 days. Everything else gets deleted.

Why? Because npm install takes under a minute for most projects. Keeping gigabytes of dependencies for projects we're not working on is a bad trade-off.

Pro Tip

If you use VS Code, it indexes node_modules by default, which can slow things down. Either delete old node_modules or add "files.watcherExclude": { "**/node_modules/**": true } to your settings.

Scan Your Projects Folder →

Finding these files too slow?

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

DissectMac Interface

Continue Reading