How to find and delete every node_modules folder on Mac

Part of our guide to why System Data is so large on Mac · Updated September 2026 · 7 min read

Every JavaScript project carries its own node_modules, often 300 MB to 2 GB. Across years of side projects, tutorials and cloned repos, that adds up to tens of gigabytes you'll never use again. The good news: node_modules is always safe to delete. Your lockfile lets you restore it exactly with one command.

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 (for example ~/Projects or ~/code). -prune stops find from descending into nested node_modules, which keeps it fast and avoids counting the same files twice.

To see which projects you haven't touched in a while, list them by last modified date:

find ~/Developer -name node_modules -type d -prune -exec stat -f "%Sm  %N" -t "%Y-%m-%d" {} + | sort

2. Delete one project's node_modules

rm -rf ~/Developer/old-project/node_modules

To get it back, run your package manager's install in that project. It reinstalls exactly the versions in your lockfile:

LockfileRestore with
package-lock.jsonnpm ci
pnpm-lock.yamlpnpm install --frozen-lockfile
yarn.lockyarn install --frozen-lockfile (Yarn 1) or yarn install --immutable (Yarn 2+)
bun.lockbun install --frozen-lockfile

Deleting with rm -rf bypasses the Trash. Don't delete node_modules in a project that's running (a dev server or watcher will crash), and check that the project has a lockfile, or a reinstall may pick up newer versions.

3. Don't forget the package manager caches

Deleting node_modules doesn't touch the global download caches, which are often several gigabytes on their own:

ToolCache location on macOSClean command
npm~/.npm/_cacachenpm cache clean --force
pnpm~/Library/pnpm/storepnpm store prune
Yarn 1~/Library/Caches/Yarnyarn cache clean
Yarn 2+~/.yarn/berry/cacheyarn cache clean --all
Bun~/.bun/install/cachebun pm cache rm

pnpm store prune is the gentlest: it removes only packages no project on your Mac references any more. The others empty the cache, so the next install downloads everything again.

Storage Cleaner's By Project view with build output and dependency folders grouped by project and when each project was last active
Seeing when each project was last active makes it obvious which dependency folders are safe to clear. (Storage Cleaner, demo data.)

Other project folders worth checking

Rather see it all at once? Storage Cleaner finds every node_modules folder, Rust target, Python venv and SwiftPM build across your projects, in one scan, shows when you last used each item and whether it's safe to remove, and cleans to the Trash with Undo. Free to scan; one payment of $2.99 to clean, yours for life.

Download free

Frequently asked

Is it safe to delete node_modules? Yes. It contains only downloaded packages. As long as the project has a lockfile, one install command restores exactly the same versions.

Why is node_modules so big? Each project keeps its own copy of every dependency and their dependencies, including native binaries for build tools. npm and Yarn 1 don't share files between projects; pnpm does, via its store, which is why it uses much less space.

Should I add node_modules to Time Machine exclusions? Yes, it's a good idea: it's large, changes constantly and can always be reinstalled. Add your projects' node_modules folders in System Settings › General › Time Machine › Options.