SweepBarGet it free

How to delete all node_modules folders at once, safely

By EgeTech LTD · October 6, 2026 · 2 min read

If you have been writing JavaScript for a year, you probably have dozens of node_modules folders scattered across old projects, and together they can take tens of gigabytes. Deleting them one by one is slow. Here is how to find them all, and how to delete only the ones you can spare.

Step 1: list them, with sizes

Point find at the folder where you keep your projects. This command lists every node_modules with its size, biggest first:

find ~/Developing -name node_modules -type d -prune -exec du -sh {} + | sort -rh

Change ~/Developing to your own projects folder. The -prune part matters: it stops find from going inside each node_modules, where it would find hundreds of nested ones and take forever.

Step 2: find the projects you have not touched

A node_modules folder is only worth deleting if you will not need the project soon. The folder’s own date is useless for this, because every install changes it. Look at your own files instead. This lists projects where package.json has not changed in 60 days:

find ~/Developing -name package.json -not -path "*/node_modules/*" -mtime +60

It is a rough signal: a project can be active without anyone editing package.json. Treat the list as a set of candidates and open it yourself before you delete.

Step 3: delete

To delete the node_modules of one project from that list:

rm -rf ~/Developing/old-project/node_modules

To delete every node_modules under a folder, including the ones in projects you are working on today:

find ~/Developing -name node_modules -type d -prune -exec rm -rf {} +

That second command has no confirmation and no undo. Run the listing from step 1 first, and only use it on a folder you are sure about. After it, every project needs npm install (or the equivalent) before it runs again.

An interactive option

npkill is an open-source tool that finds node_modules folders and lets you pick which to remove with the keyboard:

npx npkill

Run it from your projects folder.

Before you delete old projects

When you want the whole job done with a review step in the middle, the free up disk space checklist shows where else the gigabytes hide.

Quick answers

Is it safe to delete every node_modules on my Mac?

It is safe for your data, since each one can be reinstalled. It is not free: projects you work on need a reinstall, and old projects without a lockfile may install different versions.

Why not sort by the folder's modified date?

The date of node_modules changes every time you install, so it says nothing about when you last worked on the project. Look at the date of your own files instead.

Is there a tool that does this with checkboxes?

Yes. npkill is an open-source command line tool that lists node_modules folders and lets you pick which to delete. SweepBar does the same for projects you have not touched in a while.