← All guides

Is it safe to delete node_modules? (and how to get the space back)

Yes, deleting node_modules is safe: it's fully reproducible from package.json and your lockfile. Here's when to delete it, how to find every stale copy on your Mac, and how to reclaim the space.

Plumby Team3 lug 2026Updated 9 ago 20262 min read
Is it safe to delete node_modules? (and how to get the space back)

Short answer: yes. node_modules is safe to delete. It's a generated folder; every file in it is reproducible from your package.json and lockfile. Deleting it removes nothing you can't get back with a single install command.

Why it's safe

node_modules is a cache, not source. Your actual dependency list lives in package.json, and the exact resolved versions live in your lockfile (package-lock.json, pnpm-lock.yaml, or yarn.lock). When you delete node_modules and reinstall, the package manager rebuilds it to the exact same state.

The only thing you lose is the time it takes to reinstall, and disk space you probably wanted back anyway.

When you should delete it

  • Old projects you haven't touched in months. These are the biggest, safest wins.
  • Before archiving or zipping a project. Never ship node_modules.
  • When something is broken. A clean node_modules reinstall fixes a surprising number of "works on my machine" bugs.

How to bring it back

npm install      # or: pnpm install / yarn install

That's it. The folder is regenerated from your lockfile.

Finding every copy on your Mac

The real problem isn't one node_modules; it's the dozens scattered across old projects. To find them:

find ~ -name "node_modules" -type d -prune -print 2>/dev/null

To see how big they are (largest first):

find ~ -name "node_modules" -type d -prune -print0 2>/dev/null \
  | xargs -0 du -sh 2>/dev/null | sort -rh | head -20

The projects that have been idle for 180+ days are the obvious ones to clear.

Doing it without the terminal

Hunting these down by hand is tedious, and it's easy to delete the wrong thing. Plumby finds every node_modules on your machine, shows each with its size and how long it's been idle, and clears the stale ones on your command. You can send them to the Trash rather than delete, in case you change your mind. It never touches your source, just the regenerable cache.

See it, don’t guess it.
Plumby shows where your disk, memory, and processes actually go, then clears what’s safe, only when you say so.

Related guides