If you work with Node.js, React, Vue, Next.js, or any npm-based project, your Mac is probably hiding gigabytes of node_modules folders. Each project gets its own copy of every dependency, and they accumulate fast.
Typical node_modules disk usage across all projects on a developer's Mac
This guide covers how to find them all, see how much space they use, and safely delete the ones you don't need.
A typical React project can have a node_modules folder of 200-500MB. Here's why:
esbuild, swc, and sharp include native binaries for each platform.@types/* packages add up, especially in larger projects.Multiply that by 10-20 projects on your Mac, and you're looking at 5-30GB of node_modules.
# Find all node_modules directories
find ~ -name "node_modules" -type d -prune 2>/dev/null
-prune do? It prevents find from descending into node_modules directories (which contain nested node_modules). Without it, the command would be extremely slow and return duplicates.
# Only search in your projects folder
find ~/Projects -name "node_modules" -type d -prune 2>/dev/null
# Or your Desktop/Documents
find ~/Documents -name "node_modules" -type d -prune 2>/dev/null
# Count node_modules directories
find ~ -name "node_modules" -type d -prune 2>/dev/null | wc -l
# Find all node_modules and show their sizes
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null
Example output:
412M /Users/you/Projects/old-react-app/node_modules
287M /Users/you/Projects/portfolio-site/node_modules
1.2G /Users/you/Projects/work/monorepo/node_modules
156M /Users/you/Desktop/tutorial-project/node_modules
843M /Users/you/Projects/nextjs-blog/node_modules
# Show sizes sorted from largest to smallest
find ~ -name "node_modules" -type d -prune -exec du -sm {} \; 2>/dev/null | sort -rn
# Total disk usage of ALL node_modules
find ~ -name "node_modules" -type d -prune -exec du -sm {} \; 2>/dev/null | awk '{total += $1} END {print total "MB"}'
npm install (or yarn / pnpm install). It just takes a minute.
# Delete ALL node_modules on your Mac
find ~ -name "node_modules" -type d -prune -exec rm -rf {} + 2>/dev/null
# Delete node_modules only in ~/Projects
find ~/Projects -name "node_modules" -type d -prune -exec rm -rf {} + 2>/dev/null
# Delete node_modules not modified in the last 30 days
find ~ -name "node_modules" -type d -prune -mtime +30 -exec rm -rf {} + 2>/dev/null
# Not modified in the last 90 days
find ~ -name "node_modules" -type d -prune -mtime +90 -exec rm -rf {} + 2>/dev/null
npm install again.
If you want to review before deleting, use an interactive approach:
# Install and run npkill
npx npkill
npkill shows all node_modules with their sizes and lets you select which ones to delete using arrow keys + space. It's the safest option.
# Step 1: List all node_modules to a file
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null > ~/node_modules_list.txt
# Step 2: Review the file, then delete specific ones
cat ~/node_modules_list.txt # review
rm -rf /path/to/specific/project/node_modules
Besides project-level node_modules, package managers maintain global caches:
| Package Manager | Cache Location | Typical Size |
|---|---|---|
| npm | ~/.npm/_cacache | 500MB-5GB |
| yarn v1 | ~/Library/Caches/Yarn | 500MB-3GB |
| yarn v2+ | .yarn/cache (per project) | 100-500MB each |
| pnpm | ~/Library/pnpm/store | 500MB-5GB |
# npm cache
npm cache clean --force
# Check npm cache size
npm cache ls 2>/dev/null | wc -l
# yarn v1 cache
yarn cache clean
# pnpm store
pnpm store prune
# Check sizes
du -sh ~/.npm
du -sh ~/Library/Caches/Yarn 2>/dev/null
du -sh ~/Library/pnpm/store 2>/dev/null
npm install will download packages from the registry instead of using the cache. Slightly slower installs, but no functionality impact.
If you'd rather not use the terminal, there are tools that provide a visual interface:
| Tool | Type | Price | node_modules Cleanup |
|---|---|---|---|
| ClearDisk | macOS menu bar app | Free (open source) | Yes + 15 other dev caches |
| npkill | CLI (interactive) | Free (open source) | Yes (node_modules only) |
| DaisyDisk | macOS app | $9.99 | Manual (shows all files) |
| CleanMyMac | macOS app | $39-90/year | Partial (system caches) |
ClearDisk detects node_modules, npm cache, Xcode DerivedData, Docker, Homebrew, pip, CocoaPods, and more. One click to see sizes, one click to clean.
View on GitHub# Install ClearDisk via Homebrew
brew tap bysiber/cleardisk && brew install --cask cleardisk
pnpm uses a global content-addressable store and creates hard links into project node_modules. This means packages are stored once on disk, regardless of how many projects use them.
# Install pnpm
npm install -g pnpm
# Use pnpm in your projects
pnpm install
Typical savings: 50-70% less disk usage compared to npm.
Add this to your shell profile (~/.zshrc) as a quick alias:
# Add to ~/.zshrc
alias clean-nm='find ~/Projects -name "node_modules" -type d -prune -mtime +90 -exec rm -rf {} + 2>/dev/null && echo "Cleaned old node_modules!"'
Then just run clean-nm whenever you want to clean up.
Make sure every project has node_modules/ in its .gitignore. This doesn't save disk space directly, but prevents node_modules from being tracked by git (which would double the storage with git objects).
| Task | Command |
|---|---|
| Find all node_modules | find ~ -name "node_modules" -type d -prune |
| Check total size | find ~ -name "node_modules" -type d -prune -exec du -sm {} \; | awk '{t+=$1}END{print t"MB"}' |
| Delete all | find ~ -name "node_modules" -type d -prune -exec rm -rf {} + |
| Delete old (90+ days) | find ~ -name "node_modules" -type d -prune -mtime +90 -exec rm -rf {} + |
| Clean npm cache | npm cache clean --force |
| Interactive cleanup | npx npkill |
| GUI cleanup | brew tap bysiber/cleardisk && brew install --cask cleardisk |