Is it safe to delete node_modules?
Yes, for your own projects. node_modules only contains packages your package manager downloaded. It’s rebuilt from package.json and your lockfile whenever you run the install command again, so deleting it never touches your own code.
Be careful with two kinds of folders: your global packages (for example /usr/local/lib/node_modules or /opt/homebrew/lib/node_modules, which hold command-line tools such as npm itself) and folders inside apps or editor extensions (such as ~/.vscode/extensions), which those tools need to run.
1. Delete them with a Terminal command
This is the fastest way if you’re comfortable in Terminal. First see what you have and how big each folder is. Replace ~/Developer with the folder that holds your projects:
find ~/Developer -name node_modules -type d -prune -exec du -sh '{}' +
Then delete them all:
find ~/Developer -name node_modules -type d -prune -exec rm -rf '{}' +
-prune stops find from looking inside each node_modules folder, so only the top-level ones are matched. The delete is immediate and permanent: nothing goes to the Trash, there’s no list to review, and global or tool folders under that path are deleted too. Never run it on your whole home folder or on /.
2. Use npkill
npkill is a free, open-source command-line tool that lists every node_modules folder with its size and lets you pick which ones to delete. Run it from the folder you want to scan:
cd ~/Developer
npx npkill
It needs Node.js installed, runs in Terminal, and deletes permanently.
3. Use Node Modules Cleaner
Node Modules Cleaner is a native Mac app that does the same job without Terminal and with more safety checks:
- Drag your projects folder onto the window, or click Choose Folders…. Every
node_modulesfolder inside is found automatically, including nested projects and monorepos. - Review the list, sorted by size. Only project dependencies are selected. Global packages, tool folders and cloud-synced folders are flagged and left unchecked.
- Click Clean, then choose Move to Trash (reversible) or Delete Permanently (frees the space right away).
It never follows symbolic links, re-checks each folder right before removing it, and counts hard-linked files (such as pnpm’s store) only once, so the size it shows is the space you’ll actually get back. It runs offline and collects no data.
Which one should you use?
| Terminal | npkill | Node Modules Cleaner | |
|---|---|---|---|
| Shows sizes before deleting | With a separate command | Yes | Yes, including space shared through hard links |
| How you choose | Everything under the path | Pick from a list in Terminal | Check folders in a Mac window |
| Move to Trash | No | No | Yes |
| Needs Terminal or Node.js | Terminal | Both | Neither |
| Cost | Free | Free | See the Mac App Store |
How to get a project working again
Open Terminal in the project’s folder and run its install command: npm install, pnpm install, yarn or bun install. The packages download again from your lockfile, usually in under a minute.
Prefer not to use Terminal?
Node Modules Cleaner finds every node_modules folder on your Mac and shows what each one costs before you remove anything.
See Node Modules Cleaner