clenoGet cleno · $9.99

How to delete all node_modules folders on a Mac

Point find at the folder that holds your projects (here ~/Code) and list every node_modules folder in it:

find ~/Code -name node_modules -type d -prune

Check the list, then delete them by ending the same command with -exec trash {} + (macOS 15 and later, goes to the Trash) or -exec rm -rf {} + (permanent). Never run it on your whole home folder: some node_modules folders there belong to apps and tools, not your projects.

Which node_modules folders are safe to delete

The ones inside your own projects. Any project gets its folder back with one install. The rest of your home folder is a different story. On the Mac this guide was tested on, find ~ turned up 180 node_modules folders holding 14.0 GB. Only 25 of them, 11.2 GB, were in project folders. Most of the other 155 belonged to:

  • Cursor, the code editor, in ~/.cursor and ~/Library/Application Support/Cursor.
  • Discord, in ~/Library/Application Support/discord.
  • nvm's global packages, in ~/.nvm/versions/node/*/lib/node_modules. That folder holds npm itself, plus corepack and pnpm.
  • npx's cache of packages it has run, in ~/.npm/_npx.
  • A few more tools that keep their own copies, in hidden folders such as ~/.codex and ~/.cache.

Deleting those breaks the app or the tool until you reinstall it. So every command below runs on ~/Code. Replace it with your projects folder, such as ~/Developer or ~/Projects, everywhere you see it.

Step 1: list them

find ~/Code -name node_modules -type d -prune

-prune stops find from going inside a node_modules folder it has already matched. Packages often carry their own nested node_modules; without -prune you'd list those too, and a delete would trip over folders that are already gone. In a monorepo you still get each workspace's own folder, because those sit outside the root one.

Step 2: see how much space they take

Each folder with its size, largest first:

find ~/Code -name node_modules -type d -prune -exec du -sh {} + | sort -hr

The total, in GB the way Finder counts:

find ~/Code -name node_modules -type d -prune -exec du -sk {} + | awk '{ kb += $1 } END { printf "%.2f GB\n", kb * 1024 / 1e9 }'

If you use pnpm, the real saving is smaller than this. pnpm fills node_modules from a shared store, by linking or cloning files instead of copying them, so the data stays in the store until you prune it (see package manager caches below).

Step 3: delete them

These commands delete folders

Run Step 1 first and read the list. Make sure every path is inside a project.

rm -rf skips the Trash. There is no undo.

Move them to the Trash (macOS 15 Sequoia and later)

find ~/Code -name node_modules -type d -prune -exec trash {} +

trash is built into macOS 15 and later. The space comes back when you empty the Trash; until then you can drag a folder back out. On older macOS, Terminal will say trash isn't found; use the next command instead.

Delete them permanently

find ~/Code -name node_modules -type d -prune -exec rm -rf {} +

Only in projects you haven't touched lately

Add -mtime +90 to list folders not modified in 90 days:

find ~/Code -name node_modules -type d -prune -mtime +90

A node_modules folder's date changes when a package is added to it or removed from it, so this means roughly “nothing installed for 90 days”. When the list looks right, add -exec trash {} + to the end.

Step 4: get a project running again

In the project folder, run the install for its package manager. The lockfile in the project decides which one:

  • package-lock.json: npm ci (installs exactly what the lockfile says)
  • pnpm-lock.yaml: pnpm install
  • yarn.lock: yarn install
  • bun.lock or bun.lockb: bun install

With npkill instead of find

npkill is a free, open-source (MIT) command-line tool that lists these folders with their sizes and lets you pick which to delete (checked 17 Nov 2026). Run it from your projects folder:

cd ~/Code && npx npkill -t node_modules

-t node_modules limits it to node_modules; without it, npkill's default profile also looks for other Node build folders. Its README says folders that installed apps need are marked with ⚠️ and hidden unless you pass --include-sensitive, and that it finds candidates but does not decide what is safe. npx downloads it on first run, into the ~/.npm/_npx cache mentioned above.

Package manager caches

Each package manager also keeps a download cache outside your projects. Deleting node_modules doesn't touch it. These commands show where it is and clear it; the next install downloads again what it needs.

  • npm: npm config get cache shows the folder (usually ~/.npm). npm cache clean --force empties it; npm requires --force because the cache is self-healing and clearing it is only ever needed to get space back.
  • pnpm: pnpm store path shows the store (on the test Mac, ~/Library/pnpm/store/v10). pnpm store prune removes packages no project on the Mac uses, so run it after deleting node_modules folders.
  • Yarn 1: yarn cache dir shows it (on the test Mac, ~/Library/Caches/Yarn/v6). yarn cache clean empties it.

Where cleno fits

cleno doesn't look for node_modules folders today, so for these the commands above are the tool. Its Storage tab measures ~/Library/Developer (Xcode's data and simulators) and ~/Library/Caches (where Yarn's and Homebrew's caches live) and lists the largest folders in each; double-click one to show it in Finder. See what cleno does.

For big single files anywhere in your home folder, see how to find large files on a Mac. For Homebrew, see what brew cleanup removes.