## How to find and delete node_modules on a Mac

Source: https://diskcity.app/guides/delete-node-modules-mac (updated 21 October 2026)

Every JavaScript project keeps its own copy of its dependencies in a `node_modules` folder, and a single project can hold hundreds of megabytes. Across a few dozen old projects, that's often 10 to 30 GB. The good news: every one of them comes back with one install command, so old ones are safe to delete.

### Find every node_modules folder and its size

This finds the top-level `node_modules` folder in every project under your home folder (without descending into nested ones) and lists them by size:

```sh
find ~ -name node_modules -type d -prune -not -path '*/Library/*' -exec du -sh {} + 2>/dev/null | sort -rh | head -30
```

It can take a minute on a big disk. If you keep your code in one folder, run it there instead of `~` to make it faster.

### Delete the ones you don't need

Pick projects you aren't actively working on. Deleting `node_modules` loses nothing that isn't recorded elsewhere: the project's `package.json` and lock file say exactly what to reinstall.

```sh
rm -rf ~/code/old-project/node_modules
```

If you prefer a menu, `npx npkill` lists every `node_modules` folder with its size and deletes the ones you select.

### Bringing one back

When you return to a project, reinstall from its lock file so you get exactly the same versions:

- npm: `npm ci`
- pnpm: `pnpm install --frozen-lockfile`
- Yarn: `yarn install --immutable` (Yarn 2 and later) or `yarn install --frozen-lockfile` (Yarn 1)
- Bun: `bun install --frozen-lockfile`

### Clear the package manager caches too

Package managers keep their own download caches outside your projects. These are safe to clear; the next install downloads what it needs again.

```sh
npm cache clean --force
pnpm store prune
yarn cache clean
bun pm cache rm
```

pnpm's store is shared between projects through hard links, so `pnpm store prune` only removes packages no project uses any more.

### What to leave alone

Don't delete `node_modules` in a project that's running (a dev server or a build in progress), and leave globally installed tools in place unless you mean to remove them. If a project has no lock file, deleting its `node_modules` can give you newer versions on the next install, so commit a lock file first.

### How DiskCity handles node_modules

DiskCity is in development. It finds every `node_modules` folder, shows each project's size and when you last opened it, and labels them as rebuildable with the command that brings them back. You choose which to clear in a plan you approve, and git repos themselves are protected. [Join the waitlist](https://diskcity.app/) to hear when it launches.
