The node_modules folder is notorious for consuming massive amounts of disk space. A single React project can have 300MB+ of dependencies, and across 20 projects, you're looking at 6GB or more.
Here's how to safely delete node_modules folders and reclaim that space.
How to Find All node_modules Folders
Using Terminal
# Find all node_modules directories
find ~ -name "node_modules" -type d -prune 2>/dev/null
# Show sizes
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null | sort -hr
Check Total node_modules Size
# Total size of all node_modules
find ~ -name "node_modules" -type d -prune -exec du -sh {} \; 2>/dev/null | awk '{sum += $1} END {print sum "GB total"}'
How to Delete node_modules
Delete Single node_modules Folder
rm -rf /path/to/project/node_modules
Delete All node_modules Folders (Dangerous)
find ~ -name "node_modules" -type d -prune -exec rm -rf {} + 2>/dev/null
Warning: This deletes ALL node_modules folders, including active projects. You'll need to run npm install in every project.
Delete node_modules Older Than 30 Days
find ~ -name "node_modules" -type d -prune -mtime +30 -exec rm -rf {} + 2>/dev/null
Safer, but still doesn't check for uncommitted work.
The Problem with Manual Deletion
Manual deletion is risky because it doesn't consider:
- Active projects: You might delete dependencies for a project you're currently working on
- Uncommitted changes: The project might have work that depends on specific dependency versions
- Monorepos: Deleting root node_modules might break child packages
- Lock files: Without checking for package-lock.json, you might not restore exact versions
Safe node_modules Cleanup Checklist
Before deleting any node_modules folder, verify:
| Check | Why It Matters |
|---|---|
| Last modified date | Older = safer to delete |
| Git status | No uncommitted changes? |
| Has package-lock.json? | Can restore exact versions |
| Is project archived? | Might never need it again |
| Monorepo structure? | Don't break workspaces |
Skip the manual work
Cluttered finds and safely cleans all your node_modules automatically.
Using npkill (Node.js Tool)
The npkill tool helps find and delete node_modules interactively:
npx npkill
Features:
- Shows all node_modules with sizes
- Interactive selection
- Sorts by size or last modified
Limitations:
- Doesn't check git status
- No project activity analysis
- Manual selection required
Using Cluttered (Recommended)
Cluttered provides intelligent node_modules cleanup:
- Scans entire drive for Node.js projects
- Checks git status to protect uncommitted work
- Analyzes activity using file modification times
- Shows clear indicators: Green (safe), Yellow (caution), Red (active)
- Deletes to Trash for easy recovery
Why Cluttered Is Safer
| Feature | Manual/npkill | Cluttered |
|---|---|---|
| Finds all node_modules | ✅ | ✅ |
| Shows sizes | ✅ | ✅ |
| Checks git status | ❌ | ✅ |
| Detects active projects | ❌ | ✅ |
| Trash-first deletion | ❌ | ✅ |
| Cleans other ecosystems | ❌ | ✅ |
How Much Space Does node_modules Use?
Typical node_modules sizes by project type:
| Project Type | Average Size | With Dev Dependencies |
|---|---|---|
| Simple website | 50-100MB | 100-200MB |
| React app | 200-400MB | 300-600MB |
| Next.js project | 300-500MB | 500-800MB |
| Monorepo | 500MB-2GB | 1-3GB |
| Electron app | 400-800MB | 600MB-1.2GB |
Across 10-20 projects, this easily totals 5-15GB.
Reinstalling Dependencies After Cleanup
After deleting node_modules, reinstall when needed:
# Using npm
npm install
# Using yarn
yarn install
# Using pnpm
pnpm install
If you have a lock file (package-lock.json, yarn.lock, pnpm-lock.yaml), exact dependency versions are restored.
Preventing node_modules Bloat
1. Use pnpm Instead of npm
pnpm uses hard links to share packages between projects:
npm install -g pnpm
pnpm install
Can reduce total disk usage by 50-80%.
2. Regularly Clean Dormant Projects
Monthly cleanup of projects you haven't touched keeps things manageable.
3. Archive Old Projects
Before archiving to git or backup:
rm -rf node_modules
git add .
git commit -m "Archive project"
Never store node_modules in version control or backups.
4. Use .npmrc for Smaller Installs
# .npmrc
ignore-scripts=true
fund=false
audit=false
Reduces install time but not disk space.
Stop Running Out of Disk Space
Cluttered finds and cleans node_modules, Rust targets, Xcode DerivedData, Docker cache, and more. Reclaim 50-100GB in minutes.
Frequently Asked Questions
Is it safe to delete node_modules?
Yes, if you have a package.json and package-lock.json. Running npm install restores everything.
Will deleting node_modules break my project?
Only temporarily. Your next npm install restores dependencies. The project won't run until then.
How do I delete node_modules on Windows?
# PowerShell
Remove-Item -Recurse -Force node_modules
# Or use npx
npx npkill
Should I commit node_modules to git?
No. Always add node_modules to .gitignore. It's reproducible from package-lock.json.
How often should I clean node_modules?
Monthly for most developers. More often if you work on many projects or have limited disk space.
What about global npm packages?
Those are in a different location and aren't affected by project cleanup:
npm list -g --depth=0
npm cache clean --force
Conclusion
Deleting node_modules is safe when done carefully. The key is checking for active projects and uncommitted work before mass deletion.
For safe, automated cleanup, use Cluttered. It handles node_modules alongside 11 other development ecosystems, protecting your active work while reclaiming disk space.
Download Cluttered and reclaim your disk space in minutes.