Clearing npm, yarn, and pnpm Caches and node_modules on macOS
Last updated: 2026-04-06
JavaScript and TypeScript developers accumulate massive package caches over time. The npm cache at ~/.npm, yarn cache at ~/Library/Caches/Yarn, and pnpm store at ~/.pnpm-store can each grow to several gigabytes. On top of that, every project's node_modules folder contains a full copy of its dependencies — and if you have dozens of projects, that adds up to tens of gigabytes fast. These caches and folders are entirely safe to delete because they can be regenerated with a single install command.
Where npm, yarn, and pnpm store their caches
npm stores its package cache at ~/.npm (verify with `npm cache ls`). Yarn v1 uses ~/Library/Caches/Yarn, while Yarn Berry stores its cache inside each project's .yarn folder. pnpm uses a content-addressable store at ~/.pnpm-store (or ~/.local/share/pnpm/store). These caches speed up repeated installs but grow indefinitely since old package versions are never automatically removed.
The node_modules problem
Every JavaScript project has its own node_modules folder containing all resolved dependencies. A typical React or Next.js project's node_modules can be 200 MB–1 GB. If you have 20–50 projects on your Mac, node_modules alone can consume 5–15 GB. These folders are fully regenerable — running npm install, yarn install, or pnpm install recreates them from the lockfile.
How to find all node_modules on your Mac
You can use `find ~ -name node_modules -type d -prune` in Terminal, but this is slow on large filesystems and doesn't show sizes. CodeCleaner's dedicated node_modules scanner uses optimized filesystem APIs to find every instance quickly, displays sizes, supports sorting by size or last-used date, and lets you bulk-delete them with one click.
How CodeCleaner handles Node.js caches
CodeCleaner's Dev Caches module detects npm, yarn, and pnpm installations and calculates the size of each global cache. The separate node_modules Scanner finds every node_modules folder across your filesystem, lets you filter out small directories and IDE tooling paths, sort by size, and delete in bulk. Together these tools typically reclaim 5–15 GB for active JavaScript developers.
Manual steps (Terminal)
You can do this manually with these commands, or use CodeCleaner to automate the process with a visual interface and safety checks.
npm cache clean --forceyarn cache cleanpnpm store prunefind ~ -name node_modules -type d -prune -exec du -sh {} \;find ~ -name node_modules -type d -prune -exec rm -rf {} \;Or use CodeCleaner
CodeCleaner automates all of this with a native macOS app. It auto-detects your installed tools, scans the relevant paths in parallel, shows per-item sizes, and lets you clean safely with one click. Free scan, no account required.