Commands Reference
Complete reference of npm CLI commands
reference
1. Package Lifecycle Commands
- npm init – Starts an interactive wizard to create a
package.json.
Example:npm initornpm init -yto skip prompts. - npm init <template> – Generates a
package.jsonfrom a template.
Example:npm init @npmcli/init. - npm install <pkg> – Installs a package locally and records it in
dependencies.
Example:npm install lodash. - npm i <pkg>@<version> – Installs a specific version (alias for
install).
Example:npm i express@4.17.1. - npm install <pkg> --save-dev – Adds a package to
devDependencies.
Example:npm i jest --save-dev. - npm install <pkg> --global – Installs a package globally.
Example:npm i -g typescript. - npm uninstall <pkg> – Removes a package from
node_modulesandpackage.json.
Example:npm uninstall lodash. - npm update <pkg> – Updates a package to the latest compatible version.
Example:npm update express. - npm outdated – Lists packages with newer releases available.
- npm list – Shows the dependency tree of installed packages.
- npm dedupe – Eliminates duplicate packages in the tree.
- npm prune – Removes extraneous packages not listed in
package.json. - npm pack – Creates a tarball of the package for publishing.
- npm publish – Publishes the package to the npm registry.
- npm version <newversion> – Bumps the version in
package.jsonand creates a git tag.
Example:npm version patch(can also useminorormajor). - npm ci – Installs dependencies from
package-lock.jsonin a clean environment; requires a lock file. - npm run <script> – Executes a script defined in
package.json.
Example:npm run build. - npm test – Runs the test script (
npm run test). - npm start – Runs the start script.
- npm stop – Runs the stop script (rarely used).
- npm restart – Runs the restart script (rarely used).
2. Configuration Commands
- npm config set <key> <value> – Sets a configuration value.
Example:npm config set registry https://registry.npmjs.org/. - npm config get <key> – Retrieves a configuration value.
- npm config delete <key> – Removes a configuration value.
- npm config list – Lists all configuration values.
- npm config edit – Opens the config file in your default editor.
3. Authentication & Registry Commands
- npm login – Authenticates with the registry (prompts for email, username, password).
- npm logout – Logs out from the registry.
- npm whoami – Shows the current logged‑in user.
- npm adduser – Creates a new npm account or logs in.
- npm team – Manages teams for a scoped package.
- npm owner – Manages owners of a package.
4. Package Information Commands
- npm view <pkg> – Shows metadata for a package.
- npm view <pkg> <field> – Shows a specific field of the metadata.
- npm search <term> – Searches the registry for packages.
- npm info <pkg> – Alias for
npm view.
5. Auditing & Security Commands
- npm audit – Runs a security audit of installed packages.
- npm audit fix – Attempts to automatically fix vulnerabilities.
- npm audit fix --force – Forces fixes that may introduce breaking changes.
6. Miscellaneous & Utility Commands
- npm cache clean --force – Clears the npm cache (deprecated; use
npm cache verify). - npm cache verify – Verifies the integrity of the cache.
- npm link – Creates a symlink for a local package (useful for local development).
- npm unlink – Removes a symlink.
- npm completion – Generates shell completion scripts for bash, zsh, fish, etc.
- npm help <command> – Shows help for a specific command.
- npm help – Shows general help.
7. Deprecated / Legacy Commands
npm add(alias fornpm install)npm rm(alias fornpm uninstall)npm ls(alias fornpm list)
These legacy commands remain for backward compatibility but are superseded by their modern counterparts.