Disk Housekeeper

Delete node_modules safely

node_modules can be reinstalled from the lockfile. Preview every copy, keep the Trash, and do not confuse it with the npm cache.

node_modules is the installed-package folder for a JavaScript project. It is often the heaviest directory in the tree, and a laptop can hold one per checkout. It is recreatable. It is also easy to remove a copy you still need this afternoon.

Smart Clean in Disk Housekeeper can include node_modules. The npm cache is a different folder. Clearing one does not clear the other.

Steps

  1. Know which projects are active

    A monorepo can contain several node_modules directories. A dependency can contain another. You will see them in the preview. Decide before you confirm, not after.

  2. Confirm the lockfile is what you will reinstall from

    package-lock.json, pnpm-lock.yaml, or yarn.lock is the source of the next install. If a project has no lockfile and you are unsure how it was installed, leave that node_modules out of the clean.

  3. Preview, then Trash

    Disk Housekeeper always previews. Removals go to the Trash by default. Do not empty the Trash until you have reinstalled at least one project you depend on.

  4. Reinstall when you return

    Run the install command that matches the lockfile. The next install may use the npm cache if you did not clear that too. If you also want the cache gone, do it as its own step on Clean npm, Gradle, and Cargo caches.

Before you start

  • If you need to work offline, do not delete node_modules or the npm cache first. The reinstall needs the files or the network.
  • Global tools installed as packages are not the same decision as a project folder. Read the path.

Questions

Will the project remember my dependencies?

The lockfile does, if you have one. node_modules is the installed result, not the declaration. Reinstall after the clean.

Is this the same as npm cache clean?

No. The cache stores tarballs for faster installs. node_modules is the unpacked project folder. Smart Clean can show both. Remove the one you meant.