What is node_modules?
node_modules is a folder created by npm (Node Package Manager) or yarn/pnpm when you run npm install in a JavaScript/Node.js project. It contains all the third-party packages (dependencies) your project needs.
Why Does It Exist?
When a JavaScript project has a package.json file listing its dependencies, running npm install downloads all those packages (and their dependencies) into node_modules. This can result in thousands of folders and hundreds of megabytes.
Can You Delete It?
✅ Yes, it is completely safe to delete. This is one of the safest large folders to remove.
It can always be perfectly recreated by running:
npm install
Why You Should Delete It
- A single
node_modulesfolder can be 100 MB to 2 GB - If you have many projects, they collectively eat tens of gigabytes
- Old projects you’re not actively working on don’t need it sitting there
How to Delete node_modules
Simply delete the folder:
# macOS / Linux
rm -rf node_modules
# Windows (Command Prompt)
rmdir /s /q node_modules
# Windows (PowerShell)
Remove-Item -Recurse -Force node_modules
Bulk delete across many projects:
# Find and delete all node_modules (Linux/macOS)
find ~/projects -name "node_modules" -type d -prune -exec rm -rf {} +
What Happens If You Delete It?
- Your project won’t run until you
npm installagain - No code is lost, only downloaded packages are removed
- Your
package.jsonandpackage-lock.jsonremain intact - Running
npm installrestores everything exactly as it was
Bottom Line
Developers regularly delete
node_modules, it’s practically a meme in the JavaScript community. It’s always safe to delete, and it’s always one command away from being restored.
Discussion
Loading authentication...