Why do node_modules folders take up so much space?

Every JavaScript or TypeScript project installs its own copy of every dependency - and each of those dependencies can have its own nested dependencies. A single project's node_modules folder commonly reaches 200MB-1GB+, and if you have dozens of old projects sitting untouched in a Projects or repos folder, that adds up fast.

Is it safe to delete node_modules?

Yes, for any project where you have the package.json file intact. Deleting node_modules only removes the installed copies of your dependencies - running npm install, yarn, or pnpm install again rebuilds it from your package manifest and lock file. Nothing about your actual source code is affected.

How do I find every node_modules folder on my Mac?

Run this from your Projects or home directory to list every node_modules folder along with its size:

find . -name 'node_modules' -type d -prune -exec du -sh {} \;

The -prune flag is important - it stops find from recursing inside nested node_modules folders (which can be hundreds of levels deep) and re-counting the same space multiple times.

How do I delete a single node_modules folder?

rm -rf node_modules

Run this from inside the project directory. To reinstall dependencies afterward, run npm install (or your project's package manager equivalent) from the same folder.

Deleting node_modules from many projects at once

For bulk cleanup across dozens of old projects, a purpose-built tool like npkill lets you interactively browse every node_modules folder on your drive and delete the ones you choose, sorted by size. Alternatively, this one-liner deletes every node_modules folder found under the current directory:

find . -name 'node_modules' -type d -prune -exec rm -rf {} +

Caution: only run this from a folder containing projects you're confident you can reinstall dependencies for later. Skip active projects you're mid-work on, and be careful inside monorepos where a shared node_modules at the root serves multiple packages.

Will deleting node_modules speed up my Mac?

It won't affect runtime performance, but it does free up real disk space - and less clutter on your drive means faster Spotlight indexing and Time Machine backups, since neither has to churn through hundreds of thousands of small dependency files.

Finding forgotten node_modules folders alongside other space hogs

If you'd rather not hunt through Terminal, DustByte's Large & Old Files tool scans your chosen folders and sorts everything by size, so old node_modules directories show up right alongside other forgotten large files and archives.