Glossary
node_modules
The folder where a JavaScript project keeps its installed dependencies.
npm, pnpm, and Yarn install a project's packages into node_modules. The folder is local to that project, which means a machine with many checkouts holds many copies. Given the lockfile, the package manager can recreate it. Without the lockfile, you only have whatever was declared in the manifest, which is a weaker promise.
node_modules is not the npm cache. The cache stores tarballs for reuse. The project folder stores the unpacked tree the tools import. Disk Housekeeper Smart Clean can include node_modules and previews the paths before removal. The walkthrough is Delete node_modules safely.
Why node_modules gets so large
Each package you install brings its own dependencies, and those bring theirs. A project that lists twenty packages can end up with over a thousand folders of modules in node_modules. Node.js looks in this folder when your code imports a module, so it has to be there for the project to run.
Because every project has its own copy, the total across a laptop is often tens of gigabytes. Removing the copy in a project you are not working on is safe when the project has a lockfile.
Questions
What is the node_modules folder?
It is where npm, pnpm or Yarn put the packages a Node.js project depends on. It is created by the install command and can be recreated from the lockfile.
Can I delete node_modules?
Yes. Run the install command again to get it back. Keep the lockfile, which records the exact versions.
Should node_modules be committed to Git?
No. Commit the manifest and the lockfile, and add node_modules to .gitignore.