Developer cleanup

How to Clean Up node_modules on Mac (2026 Guide)

If you have been developing on a Mac for a year or more, there is a good chance that dozens of abandoned node_modules folders are quietly sitting on your disk — each one between 200 MB and several gigabytes. This guide shows you exactly how to clean up node_modules on Mac: how to find every copy, which ones are safe to delete, and the fastest ways to get that space back without breaking active projects.

Why node_modules Piles Up So Quietly

Every time you run npm install, yarn, or pnpm install, the package manager writes a full tree of dependencies into a node_modules directory next to your package.json. Nothing removes that directory when the project goes idle. A typical React app might install 700–1,000 packages; a Next.js project can install even more. Multiply that by every side project, tutorial repo, and client prototype you have cloned over the years and the total disk cost is substantial.

The good news: node_modules is always fully reproducible. As long as you still have package.json and a lockfile (package-lock.json, yarn.lock, or pnpm-lock.yaml), running the install command again rebuilds it exactly. Deleting node_modules on a stale project is zero-risk — provided the project itself is not actively running.

How Much Space Are We Talking?

The size varies wildly depending on the ecosystem, but here are realistic ballparks based on common project types:

  • A bare create-react-app project: ~250–350 MB
  • A Next.js 14/15 app with a handful of dependencies: ~400–700 MB
  • A monorepo with multiple workspaces: 1–4 GB
  • An Electron app: 1.5–3 GB (Electron itself is large)

If you have 15–30 old projects sitting around — a modest number for an active developer — the total can easily reach 20–40 GB. On a 256 GB MacBook that is a significant fraction of your usable storage.

Finding Every node_modules Folder on Your Mac

Before you delete anything, get a complete picture of what is on disk.

Option 1: The Terminal find Command

This is the most reliable method and works on any macOS version from Monterey onward. Open Terminal and run:

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

The -prune flag tells find not to recurse into each node_modules directory (which would produce millions of sub-directory results). The 2>/dev/null suppresses permission errors for directories you cannot read.

To see sizes alongside each path, pipe through du:

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

This prints a sorted list, largest first, so you immediately see which projects are costing the most space.

If you also want to search external or network drives, replace ~ with the mount point (e.g., /Volumes/MyDrive).

Option 2: npkill

npkill is a popular npm package that provides an interactive terminal UI for finding and deleting node_modules folders. As an npkill alternative on Mac, it is fine for a one-off cleanup but has a few limitations: it can be slow on large directory trees, it does not show you last-modified dates by default, and you need to have Node installed (somewhat circular). To use it without a permanent global install:

npx npkill

Navigate the list with arrow keys and press Space to delete a folder. Press q to quit.

Option 3: A GUI Tool

If you prefer not to work in Terminal, Crumb's Visualize view scans your entire Mac and shows a treemap of disk usage. Its project scanner lists every node_modules folder by size and, importantly, flags which ones belong to recently-opened projects — so you can confidently skip active work and only target stale folders. This is useful when you have a large number of projects and do not want to manually cross-reference last-modified dates.

Which node_modules Folders Are Safe to Delete?

This is the most important question, and the answer requires a bit of judgment.

Safe to delete

  • Projects you have not opened in months and are not actively running
  • Cloned tutorial repos or sample code you no longer need
  • Old client projects that have shipped and are not under active development
  • Archived repos where you still have package.json and a lockfile

Not safe to delete (or be careful)

  • Projects currently running a dev server — deleting node_modules while a process is running will crash it immediately
  • Projects where you have made local patches inside node_modules directly (a bad practice, but it happens) — those patches will be lost permanently
  • Projects with a package.json but no lockfile — reinstallation may pull newer, incompatible versions of packages
  • Globally installed tools in /usr/local/lib/node_modules or ~/.nvm/versions/node/.../lib/node_modules — do not touch these with a bulk delete

The general rule: if you have a lockfile and can run npm install again, deletion is safe. If in doubt, check when the project was last modified before removing anything.

How to Delete node_modules: Step-by-Step

Manual Terminal approach (recommended for most developers)

  1. Run the find command above with du to get a sorted list of folders and their sizes.
  2. Review the list and identify folders you want to remove. Cross-reference with your active projects.
  3. Delete a specific folder:
    rm -rf /path/to/your/project/node_modules
    Warning: rm -rf is permanent. It does not go to Trash. Double-check the path before pressing Enter.
  4. To delete all node_modules under a parent directory in one command (use with caution):
    find ~/Projects -type d -name "node_modules" -prune -exec rm -rf {} +
    Replace ~/Projects with whatever folder contains your work.
  5. Verify the space was recovered:
    df -h ~
    Or check About This Mac → Storage in System Settings.

Restoring a project afterward

Once you need the project again, cd into its directory and reinstall:

npm install
# or
yarn
# or
pnpm install

The lockfile ensures you get the same dependency versions you had before.

Comparison: Three Ways to Find and Delete node_modules on Mac

Method Speed Shows sizes Shows last-used date Safe/cautious delete
find + du in Terminal Fast Yes No (need stat separately) Manual review required
npkill (npx npkill) Moderate Yes No Interactive, one at a time
Crumb (GUI) Fast Yes Yes (flags recent projects) Visual review before delete

Preventing node_modules Bloat Going Forward

Cleaning up is a one-time fix. Here are habits that keep the problem from returning:

  • Use a global package manager cache, not per-project copies where possible. Tools like pnpm use a content-addressable store so packages are shared across projects rather than duplicated. This alone can cut your total node_modules footprint by 60–80% if you adopt it for new projects.
  • Add a calendar reminder. Every few months, run the find command and delete folders for projects you have not touched in over 90 days.
  • Archive before you forget. When a project ships or goes on hold, delete node_modules immediately. You can always reinstall; you cannot recover the disk space without actively running a cleanup.

What About Global Node Modules?

Global packages installed via npm install -g live in a separate location, typically inside your Node version manager's directory (e.g., ~/.nvm/versions/node/v22.x.x/lib/node_modules) or at /usr/local/lib/node_modules if you installed Node directly. These are usually small in total and should not be bulk-deleted — remove individual packages with npm uninstall -g <package-name> instead.

Conclusion

Cleaning up node_modules is one of the highest-return disk maintenance tasks a Mac developer can do, because the folders are large, invisible to most storage summaries, and entirely safe to delete as long as you have a lockfile. The find command covers most needs; npkill adds a light interactive layer; and if you want a full visual audit of your disk with per-project context, download Crumb and let its project scanner show you exactly what to remove and what to keep. However you approach it, a quick cleanup now can put gigabytes back in your pocket in under five minutes.

Reclaim your disk in one click

Crumb audits your whole Mac, tells you what's safe to delete, and frees the space in seconds — private, local, and Apple-notarized.

Download Crumb for macOS

Frequently asked questions

Is it safe to delete node_modules on Mac?
Yes, as long as your project still has a package.json and a lockfile (package-lock.json, yarn.lock, or pnpm-lock.yaml). Running the install command again fully rebuilds node_modules. The one exception is if you have made manual edits directly inside node_modules — those will be lost permanently.
How do I find all node_modules folders on my Mac?
Run this command in Terminal: find ~ -type d -name "node_modules" -prune -exec du -sh {} + 2>/dev/null | sort -rh. It lists every node_modules directory under your home folder, sorted largest first. Replace ~ with a specific path to search a different location.
What is a good npkill alternative on Mac?
The built-in find command (shown above) is faster and does not require any extra packages. If you want a graphical view, Crumb's Visualize feature scans your whole Mac and shows node_modules folders by size with last-used context. npkill itself also still works — run it with npx npkill without a global install.
Will deleting node_modules break my project?
Not permanently. Your source code, configuration, and lockfile remain untouched. To restore, open a terminal in the project directory and run npm install (or yarn / pnpm install). The lockfile ensures you get the same package versions as before. Avoid deleting node_modules while a dev server is actively running from that directory.