Prune

How-to

Delete old node_modules folders and get your disk space back

Every JavaScript project carries its own node_modules, often 200 MB to 1 GB. Fifty old projects can quietly add up to tens of gigabytes. They are all reinstallable, so this is the safest cleanup there is.

1. Find the big ones

# Mac
find ~ -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -rh | head -20

# Windows (PowerShell, slow on big drives)
Get-ChildItem $HOME -Directory -Recurse -Filter node_modules -ErrorAction SilentlyContinue |
  Where-Object { $_.FullName -notmatch 'node_modules\\.*node_modules' } |
  Select-Object FullName

2. Use npkill

The quickest route on both platforms, with Node installed:

cd ~/code
npx npkill

# or point it at a folder
npx npkill -d ~/code

It scans for node_modules and lists each with its size. Arrow keys move, Space deletes the highlighted folder. Start with the oldest and largest. Monorepos and pnpm workspaces can hold several node_modules in one project, so expect more than one hit per repo.

3. Or delete by hand

# Mac
rm -rf ~/code/old-project/node_modules

# Windows (PowerShell)
Remove-Item -Recurse -Force C:\code\old-project\node_modules

# Windows, if you hit "path too long" errors
npx rimraf node_modules

When you return to a project, run npm install, pnpm install or yarn. With npm ci you get exactly what the lockfile says.

What is safe and what is not

Safe: node_modules in any project you are not running, as long as it has a lockfile. Check first: the project you have open, one with no lockfile (versions may change on reinstall), one where you edited files inside node_modules by hand (commit that as a patch first), and any work you need offline.

The package manager's own cache, such as ~/.npm, is a separate and smaller job. It is safe to clear, but node_modules is where the bulk is.

Or let Prune do it

Prune lists reinstallable dependencies, including node_modules, in projects untouched for 30 days or more, and sends them to the Trash (Recycle Bin on Windows) after you approve. The free scan shows every file before you pay. Pro is $15 a year or $29 once ($19 until 20 December 2026).

FAQ

Is it safe to delete node_modules?

Yes. node_modules is rebuilt from package.json and your lockfile with npm install, pnpm install or yarn. Delete it only in projects you are not running right now.

How do I use npkill?

Run npx npkill from the folder that holds your projects, or npx npkill -d ~/code. It lists every node_modules with its size; move with the arrow keys and press Space to delete the highlighted one.

Will I lose package versions if I delete node_modules?

Not if the project has a lockfile (package-lock.json, pnpm-lock.yaml or yarn.lock), because it pins exact versions. Without one, a fresh install may pull newer versions.

Does Prune find old node_modules?

Yes. Prune lists reinstallable dependencies such as node_modules in projects untouched for 30 days or more, and sends them to the Trash or Recycle Bin after you approve.

Related