Suggest an editImprove this articleRefine the answer for “What is npm?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**npm (Node Package Manager)** is the tool for installing, updating and publishing libraries in Node.js projects; **`node_modules`** is the folder where it physically installs all of a project's dependencies. **Key point:** `package.json` describes the dependencies, `package-lock.json` pins their exact versions, and `node_modules` is where the packages actually live.Shown above the full answer for quick recall.Answer (EN)Image## What **npm** is **npm** stands for > **Node Package Manager** - *the package manager for Node.js.* ### In other words: > npm is a tool that lets you **install, update, remove and manage** libraries (packages) in Node.js projects. ## Main npm functions | Capability | What it does | |---|---| | Installing packages | Installs external libraries (`npm install express`) | | Publishing packages | Lets you publish your own package to the public npm registry | | Managing dependencies | Tracks versions, stores them in `package.json` | | Running scripts | Lets you run commands from the `scripts` section | | Caching | Stores downloaded packages locally, speeding up reinstalls | ## Example npm commands | Command | Purpose | |---|---| | `npm init` | Creates `package.json` | | `npm install` (or just `npm i`) | Installs all dependencies from `package.json` | | `npm install express` | Installs a specific package | | `npm install --save-dev nodemon` | Installs a package as a dev dependency | | `npm uninstall express` | Removes a package | | `npm update` | Updates dependencies | | `npm run <script>` | Runs a command from `"scripts"` in `package.json` | | `npm publish` | Publishes your own package to the npm registry | ## Where packages are stored after installing All packages installed via npm land in the `node_modules/` folder at the project root. ## What `node_modules` is `node_modules` is the **directory** where npm (or pnpm, yarn) installs **all of a project's dependencies**. ### Example project structure ```javascript my-app/ ├── node_modules/ │ ├── express/ │ ├── chalk/ │ ├── lodash/ │ └── ... ├── package.json ├── package-lock.json └── index.js ``` Each installed package is a folder inside `node_modules`. ## How npm and node_modules relate 1. When you install a package: ```javascript npm install express ``` 2. npm: - looks up the package **in the online npm registry** ([https://www.npmjs.com](https://www.npmjs.com)), - downloads it and all of its dependencies, - places everything in the `node_modules/` folder, - records the name and version in `package.json`. ## What `package-lock.json` is After installing, npm creates a `package-lock.json` file: - it pins the **exact versions** of every installed package and its sub-dependencies; - it guarantees an **identical install** for every developer on the project; - it speeds up repeat installs. ## Example process ```javascript npm init -y # create package.json npm install express # install the library ``` After that, the structure: ```javascript my-app/ ├── node_modules/ │ └── express/ ├── package.json └── package-lock.json ``` ## Important details ### Local vs global packages | Type | Command | Where it's installed | |---|---|---| | **Local** | `npm install express` | into `./node_modules` of the current project | | **Global** | `npm install -g nodemon` | into npm's external system directory | ### Why `node_modules` is needed - It is the **physical storage** for all of a project's dependencies. - Without it, the project won't run if dependencies aren't installed. ### Why `node_modules` is not committed to GitHub The folder can take up **hundreds of megabytes**. Instead, only these are added to the repository: - `package.json`, the list of dependencies; - `package-lock.json`, the exact versions. When cloning a project, it's enough to run: ```javascript npm install ``` and npm recreates `node_modules` from scratch. ## Summary | Concept | Description | |---|---| | **npm** | The package manager for Node.js (installs, updates, publishes libraries) | | **node_modules** | The folder where installed packages physically live | | **package.json** | Describes a project's dependencies | | **package-lock.json** | Pins exact package versions for stability |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.