npm (Node Package Manager) is the default package manager for Node.js and the world's largest registry of JavaScript packages. It installs libraries into node_modules, records them in package.json, locks exact versions in package-lock.json, and runs project scripts with npm run.
npm is installed together with Node.js, so installing a current LTS release of Node.js gives you both. Check them with node --version and npm --version. Despite the name, npm is not an acronym the project officially expands, and it is used for front-end packages, build tools and command-line tools as well as server code.
npm has three parts: the public registry at npmjs.com where packages are published, the command-line client you run in a terminal, and the package.json manifest that describes your project. Together they let you declare dependencies once and reproduce the same install on any machine or in CI.
Run npm init and answer the prompts, or use npm init -y to accept defaults. This creates package.json.
A minimal manifest looks like this:
The "type": "module" field makes .js files use ES module syntax (import and export) instead of CommonJS require.
| Command | What it does |
|---|---|
npm install | Installs every dependency listed in package.json |
npm install pkg | Installs a package and adds it to dependencies |
npm install -D pkg | Installs a development-only dependency (devDependencies) |
npm uninstall pkg | Removes a package and updates package.json |
npm ci | Clean install from package-lock.json, intended for CI and deploys |
npm update | Updates packages within the allowed version ranges |
npm outdated | Lists packages with newer versions available |
npm ls | Shows the installed dependency tree (npm list is the long form) |
npm run script | Runs an entry from the scripts field |
npx tool | Runs a package binary without installing it globally |
npm audit | Checks dependencies for known vulnerabilities |
npm publish | Publishes your package to the registry |
Avoid global installs (npm install -g) for project tools. Add them as dev dependencies and run them with npx or a script so every developer uses the same version.
npm uses semantic versioning (major.minor.patch). In a version range, ^1.4.2 allows updates that do not change the major version, and ~1.4.2 allows only patch updates. An exact version has no prefix.
| Field | Used for |
|---|---|
dependencies | Packages needed at runtime |
devDependencies | Build, test and lint tools |
peerDependencies | Packages the host project must provide, common for plugins |
optionalDependencies | Packages that may fail to install without breaking the install |
Commit package-lock.json. It pins the exact resolved version of every package, including transitive dependencies, so npm ci produces identical installs. Do not commit node_modules; add it to .gitignore.
Scripts turn long commands into short names. Local binaries from node_modules/.bin are available automatically inside scripts.
npm test and npm start have shortcuts; other scripts need npm run. Lifecycle scripts such as prepare and postinstall run automatically at certain steps, so review them in packages you do not trust.
npm audit regularly and update vulnerable packages.npm ci in CI so the lock file is respected.npm pack --dry-run, and use a files field or .npmignore.package.json; pnpm saves disk space with a shared content-addressable store.npm manages packages and runs scripts. npx executes a package binary, downloading it temporarily if it is not installed.
npm install and npm ci?npm install can update the lock file, while npm ci deletes node_modules and installs exactly what the lock file says, failing if package.json and the lock file disagree.
node_modules?No. It is large and reproducible from package.json and package-lock.json. Add it to .gitignore.
No. Node.js runs without it, but npm is bundled by default and is the usual way to install third-party packages.
npm installs and versions JavaScript packages, runs project scripts and publishes your own. Keep package.json accurate, commit package-lock.json, use npm ci in automated builds, run npm audit, and prefer local dev dependencies over global installs.