How to find and delete every node_modules folder on Mac
Every JavaScript project carries its own node_modules, often 300 MB to 2 GB. Across years of side projects, that adds up to tens of gigabytes you'll never use again.
1. Find them all, with sizes
find ~/Developer -name node_modules -type d -prune -exec du -sh {} + | sort -h
Replace ~/Developer with wherever you keep your code. -prune stops find from descending into nested node_modules, which keeps it fast.
2. Delete one project's node_modules
rm -rf ~/Developer/old-project/node_modules
Run npm install (or pnpm install, yarn, bun install) in that project to get it back.
3. Or use an interactive tool
npx npkill
npkill lists every node_modules below the current folder and lets you delete them one keypress at a time.
Deleting with rm -rf or npkill bypasses the Trash. Make sure the project isn't one you're about to run.
Don't forget the package manager caches
| Tool | Cache location | Clean command |
|---|---|---|
| npm | ~/.npm/_cacache | npm cache clean --force |
| pnpm | ~/Library/pnpm/store | pnpm store prune |
| Yarn | ~/Library/Caches/Yarn | yarn cache clean |
| Bun | ~/.bun/install/cache | bun pm cache rm |
Rather not do this by hand? Storage Cleaner finds every node_modules folder across your projects in one scan, shows when you last used each one, and removes them safely with Undo.
Try Storage Cleaner free