How to delete node_modules folders on a Mac

Every JavaScript or TypeScript project you install gets a node_modules folder, and together they can take tens of gigabytes. Here are three ways to find them all and delete them, from a one-line Terminal command to a Mac app that shows you what you’re removing first.

Updated October 28, 2026 · 4 minute read

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:

  1. Drag your projects folder onto the window, or click Choose Folders…. Every node_modules folder inside is found automatically, including nested projects and monorepos.
  2. Review the list, sorted by size. Only project dependencies are selected. Global packages, tool folders and cloud-synced folders are flagged and left unchecked.
  3. 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?

TerminalnpkillNode Modules Cleaner
Shows sizes before deletingWith a separate commandYesYes, including space shared through hard links
How you chooseEverything under the pathPick from a list in TerminalCheck folders in a Mac window
Move to TrashNoNoYes
Needs Terminal or Node.jsTerminalBothNeither
CostFreeFreeSee 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