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-appproject: ~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.jsonand a lockfile
Not safe to delete (or be careful)
- Projects currently running a dev server — deleting
node_moduleswhile a process is running will crash it immediately - Projects where you have made local patches inside
node_modulesdirectly (a bad practice, but it happens) — those patches will be lost permanently - Projects with a
package.jsonbut no lockfile — reinstallation may pull newer, incompatible versions of packages - Globally installed tools in
/usr/local/lib/node_modulesor~/.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)
- Run the
findcommand above withduto get a sorted list of folders and their sizes. - Review the list and identify folders you want to remove. Cross-reference with your active projects.
- Delete a specific folder:
Warning:rm -rf /path/to/your/project/node_modulesrm -rfis permanent. It does not go to Trash. Double-check the path before pressing Enter. - To delete all
node_modulesunder a parent directory in one command (use with caution):
Replacefind ~/Projects -type d -name "node_modules" -prune -exec rm -rf {} +~/Projectswith whatever folder contains your work. - Verify the space was recovered:
Or check About This Mac → Storage in System Settings.df -h ~
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
pnpmuse a content-addressable store so packages are shared across projects rather than duplicated. This alone can cut your totalnode_modulesfootprint by 60–80% if you adopt it for new projects. - Add a calendar reminder. Every few months, run the
findcommand 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_modulesimmediately. 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.