What does node_modules store?
node_modules is the folder where npm (or yarn/pnpm) stores all of a project's installed dependencies, along with their nested dependencies.
What exactly is in there
- Core dependencies from
package.json(dependenciesanddevDependencies) Every installed package ends up innode_modules. - Nested dependencies
If your library depends on another library, that one gets installed inside
node_modulestoo, even if you never listed it directly. - Compiled artifacts Some packages contain compiled binary files (for example, for Node modules written in C/C++).
- npm ecosystem service files
For example,
.bin, a folder with executable files for CLI packages.
Notable traits
-
A large structure
node_modulescan take up hundreds of megabytes or even gigabytes because of nested dependencies. -
Not stored in the repository This folder is usually added to
.gitignore, because it is easily restored with the command:bashnpm install -
Readability is secondary The folder is not meant for manual editing, it is npm's internal structure.
Summary
node_modules stores the full set of libraries a project needs to run, including their nested dependencies and service files. It is effectively an "installed version of the ecosystem", built from the data in package.json and package-lock.json.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.