Every JavaScript project has a node_modules, often 300 MB to 1 GB. With twenty projects, or a few git worktrees per project, that's tens of GB of files npm install can download again in a minute. Rust's target, Python's .venv, CocoaPods' Pods and Next.js'.next work the same way.
Find every node_modules and its size
From the folder that holds your projects:
cd ~/Developerfind . -name node_modules -type d -prune -exec du -sh {} + | sort -h
-prune stops find from descending into a node_modules it already found, so you get one line per project and not thousands.
Delete them
Everything older than 30 days:
find . -name node_modules -type d -prune -mtime +30 -exec rm -rf {} +
Or pick them one by one with npkill, which lists every node_modules with its size and deletes the one you select:
npx npkill
Is it safe?
Yes, as long as the project has a package.json (and preferably a lock file) next to it: then npm install, pnpm install or yarn brings back exactly the same. Be careful with folders that are not in a project, and with anything a process is using right now: delete node_modules under a running dev server and it crashes.
The other build folders
# Rustfind . -name target -type d -prune -exec test -f {}/../Cargo.toml ';' -print# Python virtual environmentsfind . -name .venv -type d -prune# CocoaPods and Next.jsfind . \( -name Pods -o -name .next \) -type d -prune
Inside a project, cargo clean empties target. And the package managers keep a global cache next to all this: npm cache clean --force, pnpm store prune, yarn cache clean.
Or let Sluice do it
Sluice finds node_modules, Rust target, .venv, .next, Pods and more in your code folders, and only offers them when the file that recreates them sits next to them. Sluice is free to download and clean with; Pro cleans every night and whenever space runs low.
macOS 14 Sonoma or later · Apple silicon and Intel · or brew install --cask qraft/tap/sluice