---
title: "Delete node_modules safely · MacMelon"
description: "Remove node_modules with a preview and the Trash, then reinstall from the lockfile. Separate this from clearing the npm cache."
url: "https://macmelon.com/use-cases/delete-node-modules-safely"
---

# 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](https://macmelon.com/glossary/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](https://macmelon.com/apps/disk-housekeeper) can include node\_modules. The [npm cache](https://macmelon.com/glossary/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](https://macmelon.com/use-cases/clean-developer-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.

## Apps

[Make room for what matters. Clear clutter with confidence. ### Disk Housekeeper](https://macmelon.com/apps/disk-housekeeper)

## Related guides

[### How to clean developer files on macOS](https://macmelon.com/guides/how-to-clean-developer-files-on-macos)

## Related use cases

[### Clean npm, Gradle, and Cargo caches](https://macmelon.com/use-cases/clean-developer-caches)[### Free up space on a MacBook](https://macmelon.com/use-cases/free-up-space-on-a-macbook)[### Clear Xcode DerivedData](https://macmelon.com/use-cases/clear-xcode-deriveddata)

## Related terms

[The folder where a JavaScript project keeps its installed dependencies. ### node\_modules](https://macmelon.com/glossary/node-modules)[npm's on-disk store of package tarballs, reused by later installs. ### npm cache](https://macmelon.com/glossary/npm-cache)[The holding area macOS uses for files you have deleted but not yet erased. ### Trash](https://macmelon.com/glossary/trash)[A required look at the files a clean will touch, before anything is removed. ### Preview before cleaning](https://macmelon.com/glossary/preview-before-cleaning)[Disk Housekeeper's cleaner for developer caches and node\_modules, behind a preview. ### Smart Clean](https://macmelon.com/glossary/smart-clean)

## Related notes

[node\_modules is recreatable from a lockfile, and it is also easy to remove the wrong copy. A preview and the Trash are the difference. ### Deleting node\_modules without regretting it](https://macmelon.com/blog/deleting-node-modules-without-regrets)
