I reclaimed 47 GB by deleting old node_modules — script + pitfalls
A 3-year-old dev machine can hold 50–100 GB of dead node_modules. Here's how to find and remove them safely, plus the target/, .venv, Pods/ folders you probably forgot.
After 3 years freelancing, I opened Finder and counted: 87 folders in ~/Dev. Each one is a Laravel / Vue / Next / React Native / Astro / whatever project — most of them shipped long ago, clients signed off, and I haven’t touched them since 2023.
But their node_modules were still sitting there. Silent. Heavy.
That day I ran:
find ~/Dev -type d -name "node_modules" -prune 2>/dev/null \
-exec du -sh {} + | sort -hr
Output: 73 lines. Sum total: 47 GB.
This is the post I wrote after recovering those 47 GB — how to find, how to delete safely, and the traps I stepped in so you don’t have to.
Step 1: Find every node_modules
Basic command:
find ~ -type d -name "node_modules" -prune 2>/dev/null \
-exec du -sh {} + | sort -hr
The critical flag is -prune: once find hits a node_modules, it stops descending into it. Without -prune, it walks into nested node_modules/*/node_modules/... and on macOS this loops forever (painfully slow).
2>/dev/null swallows the “Permission denied” noise from ~/Library.
To scan only your main dev folders:
find ~/Dev ~/Sites ~/Workspace -type d -name "node_modules" -prune \
-exec du -sh {} + 2>/dev/null | sort -hr
Step 2: Decide what’s safe to delete
The first trap I fell into: I thought “old project from 2022, nuke it all.” Two weeks later an old client emailed — “can you fix this bug for me?” I opened the project, npm install, and 8 packages had been deprecated on npm in the meantime. 3 of them had been completely removed from the registry (maintainer yanked them, license issue, whatever). I spent a day hunting forks on GitHub to patch things up.
Lesson: node_modules is sometimes a time capsule of the exact package versions you tested and shipped against. Delete it and that’s gone.
My current rule of thumb:
| Project type | Still maintaining? | Safe to delete? |
|---|---|---|
| My own side project | Untouched 6+ months | ✅ Yes |
| Client work, in warranty | Within 1 year | ⚠️ Only if package-lock.json exists and is committed |
| Client work, closed | > 2 years | ✅ Yes |
| Company project | Any time | ✅ (CI can rebuild) |
Check before deleting a specific project:
cd ~/Dev/some-old-project
# Is there a lockfile?
ls package-lock.json yarn.lock pnpm-lock.yaml 2>/dev/null
# Was it committed?
git log --oneline package-lock.json 2>/dev/null | head
Lockfile present + committed → delete freely. npm ci later rebuilds the exact same tree.
Step 3: Delete
Single project:
rm -rf node_modules
Many projects at once — this only deletes top-level node_modules inside ~/Dev, never nested:
find ~/Dev -type d -name "node_modules" -prune -print \
-exec rm -rf {} +
Warning: running this without -prune will wipe active projects too. Always -print first to dry-run the list.
Want extra safety? Use Trash instead of rm:
brew install trash
find ~/Dev -type d -name "node_modules" -prune -exec trash {} +
If you slip, Cmd+Z in Finder or restore from Trash.
It’s not just node_modules
After the node_modules sweep I found several other folders eating comparable space. The full list:
| Folder | Ecosystem | Typical size |
|---|---|---|
node_modules/ | JS/TS | 200 MB – 2 GB |
target/ | Rust | 500 MB – 5 GB |
build/ | Java/Gradle | 300 MB – 3 GB |
.gradle/ | Android | 1 – 8 GB |
.venv/ or venv/ | Python | 200 MB – 2 GB |
Pods/ | iOS CocoaPods | 100 MB – 1 GB |
vendor/ | Laravel/Composer | 100 MB – 500 MB |
.next/ | Next.js build | 100 MB – 1 GB |
dist/ | many | 50 MB – 500 MB |
DerivedData/ | Xcode | 1 – 10 GB per project |
Scan them all in one pass:
find ~/Dev -type d \
\( -name "node_modules" -o -name "target" -o -name ".venv" \
-o -name "venv" -o -name "Pods" -o -name ".next" \) \
-prune -exec du -sh {} + 2>/dev/null | sort -hr | head -30
On my machine, this second sweep surfaced another 31 GB — mostly target/ from old Rust projects and Pods/ from 3 iOS apps I’d shipped in 2021.
The bottom line
That cleanup recovered 78 GB total — 47 GB from node_modules plus 31 GB from everything else. On a 512 GB MacBook Pro, that’s 15% of disk.
More important than the number: Spotlight reindexes faster, Time Machine backups are leaner, and I no longer hit “Storage Almost Full” mid-build.
Haven’t read my overview of the 7 places your GB goes on macOS yet? Pair it with this one.
Doing this by hand is fine, but I don’t want to run those commands every month. That’s why I built Molecule Dev Purge — it scans every dev folder above, shows size + last-modified, and lets you tick which groups to delete. Native macOS, zero telemetry, free.