node_modules is eating your disk: how to find and clean old JavaScript projects
If you've ever built a website, an app, or even followed a JavaScript tutorial, you have node_modules folders sitting on your disk. Each one is a complete copy of every dependency that project needs — and they are enormous.
A typical React project's node_modules weighs 200–400 MB. A Next.js or Gatsby project can hit 500 MB–1 GB. If you have ten old projects you haven't touched in months, that's potentially 5–10 GB of files you'll never use again, quietly eating your disk.
Why node_modules gets so big
When you run npm install, npm downloads every package your project lists — plus every package those packages depend on, and so on. A project with 30 direct dependencies can end up with 800+ packages in its node_modules folder. Each package includes source code, tests, readmes, and sometimes native binaries.
Unlike system-level package managers that share libraries between projects, npm gives each project its own copy of everything. This avoids version conflicts, but it means the same packages get duplicated across every project on your machine.
How to find every node_modules on your Mac
Open Terminal and run:
find ~ -name "node_modules" -type d -prune -maxdepth 5
Here's what each part means in plain English:
~— start from your home folder-name "node_modules"— look for directories named exactly "node_modules"-type d— only match directories, not files-prune— don't look inside the node_modules folders themselves (they contain nested node_modules, and you don't want to list those)-maxdepth 5— don't dig more than 5 levels deep, which keeps the search fast
To see how much space each one takes, add du -sh:
find ~ -name "node_modules" -type d -prune -maxdepth 5 -exec du -sh {} \;
This will print something like:
412M /Users/you/projects/old-blog/node_modules
891M /Users/you/projects/startup-mvp/node_modules
234M /Users/you/projects/tutorial-react/node_modules
Deleting them is safe — here's why
A node_modules folder contains only downloaded packages. Your actual code lives in src/, your dependency list lives in package.json and package-lock.json (or yarn.lock). Deleting node_modules removes nothing you wrote and nothing that can't be rebuilt.
If you ever need that project again, just run npm install in the project folder and everything comes back, exactly as it was.
To delete a specific one:
rm -rf ~/projects/old-blog/node_modules
npm install to re-download everything before you can continue. Only clean up projects you're done with or haven't touched in a while.npkill: the visual way
If you'd rather not type paths manually, npkill is an open-source tool that lists every node_modules it finds, shows sizes, and lets you delete them one by one with the spacebar. Run it without installing permanently:
npx npkill
It opens a terminal interface showing each project and its node_modules size. Arrow keys to navigate, Space to delete. Simple and satisfying.
Living with it: pnpm and shared storage
If you work on many JavaScript projects regularly, consider switching to pnpm. Instead of copying every package into every project, pnpm stores one copy of each package version in a global store and creates links to it. The result: node_modules folders become tiny, and disk usage drops dramatically.
pnpm is a drop-in replacement for npm — same commands, same package.json, just prefix with pnpm instead of npm.
The bigger picture: developer clutter
node_modules is the most visible disk hog, but it's not the only one. Package manager caches (npm, yarn, pnpm, Cargo, Gradle) can add another 10–20 GB, and macOS often lumps all of this into a mysterious "System Data" category that gives no breakdown. If your Mac is running low on space, node_modules cleanup is a great first step — but it's usually not the last one.
Let your Mac find all of this for you
Gigatidy scans your disk, spots every node_modules and developer cache, shows you the total, and lets you clean up in one step — no Terminal needed.
Meet Gigatidy →FAQ
Will deleting node_modules break my project?
No. Your source code and dependency list (package.json, lock file) are separate files. Run npm install in the project folder to restore everything exactly as it was.
How often should I clean up node_modules?
Whenever you finish a project or haven't touched one in a few months. There's no need for a schedule — just check when you're running low on disk space.
Does this apply to yarn and pnpm projects too?
Yes. Yarn creates node_modules the same way npm does (unless you're using Yarn PnP). pnpm creates a node_modules folder too, but it's mostly symlinks — much smaller. The find command above catches all of them.