Purplelink
← All guides

node_modules is filling my Mac: find and delete them safely

Every JavaScript project keeps its own node_modules folder, and old projects keep theirs for years. This guide says what the folder is, when you can delete it, how to find every copy with a read-only command, and which similar-looking folders to leave alone.

Disclosure up front: Purplelink, which publishes this site, makes one app mentioned near the end, Legroom, a menu-bar app sold as a 7-day trial and a $9.99 one-time purchase. I ran the commands below on my own Mac on November 30, 2026 (macOS 27.2.1, Node 24.21.0, npm 11.19.0). The two find commands only read. I tested the delete and reinstall steps on a small test project (3 packages, 3.6 MB) in a temporary folder, and the npm cache commands on a separate test cache. pnpm is not installed on this Mac and I did not run npkill, so what I say about both comes from their makers' pages, which I link. Sizes are from one Mac and yours will differ.

The short answer

A node_modules folder holds the packages one JavaScript project depends on. You can delete it in any project you can reinstall, which means a project that still has its package.json and its lock file. Find the folders with a read-only command, check that each one sits beside a package.json, and move the ones you do not need to the Trash. Leave alone any node_modules that sits inside an app, an editor extension or another tool's own folder.

What node_modules is

When you run npm install in a project, npm puts the packages in a folder named node_modules at the project's root. npm's page on folders describes this as a local install. Every project gets its own copy, so ten projects that use the same library hold ten copies of it. The folder is output. Your own code and the list of what to install live outside it.

When it is safe to delete

It is safe when three things hold:

To get the folder back, run npm install or npm ci in the project folder. npm's page on npm ci says the command needs a lock file, removes any existing node_modules before it installs, and never writes to package.json or the lock file. On my test project, npm ci returned the same 3 packages at the same 3.6 MB.

Find them first

This command lists every node_modules folder under one folder. It only reads. Replace ~/Developer with the folder that holds your projects.

find ~/Developer -name node_modules -type d -prune

The -prune part stops find from looking inside a node_modules once it has found one, so you get one line per project and not thousands of nested results. To see the size of each, add du:

find ~/Developer -name node_modules -type d -prune -exec du -sh {} +

Point the command at your projects folder, not at your whole home folder. A search from the home folder also returns the copies inside apps and editor extensions, which you should not delete (see what not to delete).

On my Mac the command returned one folder of 400 KB, and it was not a project of mine. It sat inside a Python package (.venv/lib/python3.12/site-packages/gradio/) that ships its own JavaScript. This is why the next step matters: before you delete a result, check that a package.json you recognise sits in the same folder.

Delete the ones you do not need

Use the Trash first, so a mistake can be undone. In Finder, press Shift-Command-G, paste the path from the list, and drag node_modules to the Trash. In Terminal, from inside the project folder:

trash node_modules

The trash command exists on macOS 27.2.1, where I ran it. If your Mac answers "command not found", use Finder. Many pages suggest rm -rf node_modules. It works, but it deletes at once with no undo, and a typo in the path deletes something else.

The space comes back when you empty the Trash. If the number in Storage does not move after that, the guide on why a Mac still says storage is full after deleting files lists the usual reasons.

npkill, an interactive option

npkill is a free, MIT-licensed tool that lists node_modules folders with their sizes and deletes the one you select. Its README says you start it with npx npkill, that it searches from the folder where you run it, and that Space or Del deletes the selected folder. Two of its options are useful here: --dry-run deletes nothing, and -d sets the starting folder. The README also warns that some installed applications need their node_modules, and it marks those results with a warning sign. It does not say whether a deleted folder goes to the Trash, so treat the deletion as permanent. I did not run it.

The shared caches are a different thing

Deleting node_modules does not touch the caches the package managers keep in your home folder.

WhatWhereMaker's command
npm cache~/.npm (data in _cacache)npm cache verify
pnpm storeprinted by pnpm store pathpnpm store prune

npm. npm's page on the cache says the cache grows as you install packages and that npm does not remove data from it by itself. npm cache verify checks the contents and garbage collects data that is no longer needed. npm cache clean --force empties the cache. The page says clearing should not be needed other than to reclaim disk space, which is why npm asks for --force. On my test cache, verify reported 3 entries (1.8 MB), clean without --force refused, and clean --force left 20 KB of logs.

pnpm. pnpm keeps one store for the whole Mac and hard-links or clones files from it into each project (pnpm's motivation page). Its FAQ says the same space is addressed from two locations. pnpm's pages give no figure, so this next point is my inference: deleting one pnpm project's node_modules frees little while the store still holds the files. The command that frees store space is pnpm store prune. pnpm's page on the store says it removes packages that no project on the system references, and that it downloads them again when a project needs them.

What not to delete

Where Legroom fits

Legroom is the app I make. Three parts of version 1.15.0 deal with these folders, and they behave differently.

Legroom also has presets for the npm cache (~/.npm/_cacache), npx packages (~/.npm/_npx) and the pnpm metadata cache (~/Library/Caches/pnpm). It never touches the pnpm store. The find command above does the finding for free, and the guide on disk space analyzers for Mac compares several tools. Legroom is here.

Frequently asked

Can I delete the node_modules folder?

Yes, for a project you can reinstall. The folder holds copies of the packages listed in package.json, and npm install or npm ci downloads them again. Keep package.json and the lock file. Stop any dev server or build that uses the project first.

Will deleting node_modules break my project?

The project will not run until you reinstall. Run npm ci, npm install or pnpm install in the project folder and the packages return. On one test project with 3 packages, the folder came back at the same 3.6 MB after npm ci. Changes you made by hand inside node_modules do not return.

Does deleting node_modules free space at once?

Only when the files are gone for good. A folder in the Trash still takes space until you empty the Trash. Free space can also lag after that, because macOS may hold local snapshots for a while.

Is the npm cache the same thing as node_modules?

No. node_modules sits inside each project. The npm cache is one shared folder, ~/.npm by default, that npm reads when it installs. npm's documentation says the cache grows as you install packages and that npm does not remove data from it by itself.

Should I delete node_modules inside an app?

No. Some apps ship their own node_modules inside the app bundle, and editor extensions keep one in their own folders. Those belong to the app. Delete only the ones that sit beside a package.json in a project of yours.

Related guides