NPM commands

Node Package Manager — the default package manager for Node.js

220 commands

Init & Config

  • npm init

    Interactively create a package.json file

  • npm init -y

    Create a package.json file with all defaults, skipping prompts

  • npm init --scope=@myorg

    Initialize a scoped package interactively

  • npm set init-author-name "John Doe"

    Set default author name used during npm init

  • npm set init-author-email "john@example.com"

    Set default author email used during npm init

  • npm set init-license "MIT"

    Set default license used during npm init

  • npm config set registry https://registry.npmjs.org/

    Set the default npm registry URL

  • npm config get registry

    Get the currently configured npm registry URL

  • npm config delete registry

    Remove the registry config key, reverting to default

  • npm config list

    List all active npm configuration values

  • npm config list --json

    List all npm config values in JSON format

  • npm config edit

    Open the global .npmrc file in the default editor

  • npm config set save-exact true

    Configure npm to save exact versions instead of semver ranges

  • npm config set save-prefix "~"

    Set the default semver prefix used when saving dependencies

  • npm config set proxy http://proxy.example.com:8080

    Set an HTTP proxy for npm network requests

  • npm config set https-proxy http://proxy.example.com:8080

    Set an HTTPS proxy for npm network requests

  • npm config set cache /path/to/cache

    Set a custom directory for the npm cache

Install & Add Packages

  • npm install

    Install all dependencies listed in package.json

  • npm install --production

    Install only production dependencies, skipping devDependencies

  • npm install --only=dev

    Install only devDependencies

  • npm install --frozen-lockfile

    Install dependencies without updating package-lock.json

  • npm install --legacy-peer-deps

    Install packages ignoring peer dependency conflicts

  • npm install --force

    Force reinstall of all packages, bypassing cache and lock

  • npm install --ignore-scripts

    Install packages without running any lifecycle scripts

  • npm install --prefer-offline

    Use cached packages when available, falling back to network

  • npm install --prefer-online

    Force network fetch even when cached packages are available

  • npm install express

    Install the latest version of the express package as a dependency

  • npm install express@4.18.2

    Install a specific version of the express package

  • npm install express@latest

    Install the latest tagged version of the express package

  • npm install express@^4.0.0

    Install express at the latest version satisfying the given semver range

  • npm install express --save

    Install express and explicitly add it to dependencies in package.json

  • npm install express --save-exact

    Install express and pin the exact version in package.json

  • npm install typescript --save-dev

    Install typescript as a development dependency

  • npm install typescript --save-dev --save-exact

    Install an exact version of typescript as a devDependency

  • npm install lodash --save-optional

    Install lodash as an optional dependency

  • npm install -g typescript

    Install typescript globally on the system

  • npm install -g npm@latest

    Update npm itself to the latest version globally

  • npm install react react-dom

    Install multiple packages simultaneously as dependencies

  • npm install @types/node --save-dev

    Install a scoped package as a devDependency

  • npm install git+https://github.com/user/repo.git

    Install a package directly from a GitHub repository URL

  • npm install github:user/repo

    Install a package from a GitHub shorthand reference

  • npm install github:user/repo#branch

    Install a package from a specific branch of a GitHub repository

  • npm install ./path/to/local-package

    Install a package from a local directory path

  • npm install file:./packages/my-lib

    Install a local package using the file: protocol

  • npm install https://example.com/package.tgz

    Install a package from a remote tarball URL

  • npm install --no-save express

    Install express without modifying package.json

  • npm install --dry-run express

    Simulate installing express without making any actual changes

  • npm install --verbose express

    Install express with verbose output for debugging

Uninstall & Remove Packages

  • npm uninstall express

    Remove express from node_modules and package.json dependencies

  • npm uninstall express --save

    Remove express from node_modules and explicitly remove from dependencies

  • npm uninstall typescript --save-dev

    Remove typescript from node_modules and devDependencies

  • npm uninstall lodash --save-optional

    Remove lodash from node_modules and optionalDependencies

  • npm uninstall -g typescript

    Remove a globally installed package

  • npm uninstall --no-save express

    Remove express from node_modules without modifying package.json

  • npm uninstall react react-dom

    Remove multiple packages simultaneously

Update Packages

  • npm update

    Update all packages to the latest version within their semver range

  • npm update express

    Update express to the latest version within its semver range

  • npm update --save

    Update all packages and persist updated versions to package.json

  • npm update -g

    Update all globally installed packages

  • npm update -g typescript

    Update a specific globally installed package

  • npm update --depth 2

    Update packages up to 2 levels deep in the dependency tree

Scripts & Execution

  • npm run build

    Execute the build script defined in package.json scripts

  • npm run dev

    Execute the dev script defined in package.json scripts

  • npm run test

    Execute the test script defined in package.json scripts

  • npm run lint

    Execute the lint script defined in package.json scripts

  • npm run format

    Execute the format script defined in package.json scripts

  • npm run start

    Execute the start script defined in package.json scripts

  • npm start

    Run the start script shorthand (no run keyword needed)

  • npm test

    Run the test script shorthand (no run keyword needed)

  • npm run build -- --watch

    Pass additional arguments to a script after the double-dash separator

  • npm run build --if-present

    Run the build script only if it exists, without erroring if absent

  • npm run env

    List environment variables available to scripts at runtime

  • npm exec tsc

    Execute a locally installed binary from node_modules/.bin

  • npm exec -- tsc --init

    Execute a local binary with arguments using the double-dash separator

  • npx create-react-app my-app

    Run a package binary without installing it permanently

  • npx --yes create-next-app my-app

    Run a package binary, auto-confirming installation prompts

  • npx --no-install tsc

    Run a local binary only, without fetching from registry if missing

  • npx -p typescript tsc --init

    Specify a package to install and then run its binary

Workspaces

  • npm install --workspaces

    Install dependencies for all workspaces in a monorepo

  • npm install --workspace=packages/app

    Install dependencies for a specific workspace by path

  • npm run build --workspaces

    Run the build script across all workspaces

  • npm run build --workspace=packages/app

    Run the build script in a specific workspace

  • npm run test --workspaces --if-present

    Run test script across all workspaces only where it exists

  • npm install lodash --workspace=packages/app

    Install a package into a specific workspace

  • npm exec --workspace=packages/app -- tsc

    Execute a binary in the context of a specific workspace

  • npm pkg get name --workspaces

    Get the name field from package.json for all workspaces

Publish & Registry

  • npm publish

    Publish the current package to the npm registry

  • npm publish --access public

    Publish a scoped package publicly to the npm registry

  • npm publish --access restricted

    Publish a package as restricted (private)

  • npm publish --tag beta

    Publish the package under a custom dist-tag instead of latest

  • npm publish --dry-run

    Simulate publishing without uploading anything to the registry

  • npm publish --otp 123456

    Publish using a one-time password for 2FA-enabled accounts

  • npm unpublish my-package@1.0.0

    Remove a specific version of a package from the registry

  • npm unpublish my-package --force

    Force-remove an entire package from the registry

  • npm deprecate my-package@1.0.0 "Use v2 instead"

    Mark a specific package version as deprecated with a message

  • npm dist-tag add my-package@1.0.0 stable

    Add a dist-tag pointing to a specific version

  • npm dist-tag rm my-package beta

    Remove a dist-tag from a package

  • npm dist-tag ls my-package

    List all dist-tags for a package

  • npm pack

    Create a .tgz tarball of the current package without publishing

  • npm pack --dry-run

    List files that would be included in the tarball without creating it

Authentication

  • npm login

    Log in to the npm registry interactively

  • npm login --registry https://registry.npmjs.org/

    Log in to a specific npm registry

  • npm login --scope=@myorg

    Associate a scope with a specific registry and log in

  • npm logout

    Log out from the npm registry, removing auth tokens

  • npm logout --registry https://registry.npmjs.org/

    Log out from a specific registry

  • npm whoami

    Display the currently authenticated npm username

  • npm whoami --registry https://registry.npmjs.org/

    Display the authenticated username for a specific registry

  • npm token list

    List all authentication tokens for the current account

  • npm token create

    Create a new authentication token

  • npm token create --read-only

    Create a read-only authentication token

  • npm token create --cidr 192.168.1.0/24

    Create a token restricted to a specific CIDR IP range

  • npm token revoke abc123

    Revoke a specific authentication token by its ID or value

Info & Search

  • npm info express

    Display metadata for the express package from the registry

  • npm info express version

    Display only the latest version of express

  • npm info express versions

    List all published versions of express

  • npm info express dependencies

    Display the dependencies of the latest express version

  • npm info express --json

    Display full package metadata in JSON format

  • npm view express

    Alias for npm info — display registry metadata for a package

  • npm view express@4.18.2 dependencies

    Show dependencies for a specific version of express

  • npm search lodash

    Search the npm registry for packages matching a keyword

  • npm search lodash --json

    Search the npm registry and return results as JSON

  • npm search --searchlimit 20 lodash

    Search npm with a limit on the number of results returned

  • npm docs express

    Open the documentation homepage for the express package in a browser

  • npm repo express

    Open the repository URL for the express package in a browser

  • npm bugs express

    Open the issue tracker for the express package in a browser

  • npm home express

    Open the homepage of the express package in a browser

Listing & Dependency Tree

  • npm list

    List installed packages and their dependency tree in the current project

  • npm list --depth=0

    List only top-level installed packages without sub-dependencies

  • npm list --depth=1

    List installed packages up to one level of sub-dependencies

  • npm list --json

    Output the installed dependency tree in JSON format

  • npm list --production

    List only production dependencies in the tree

  • npm list --dev

    List only development dependencies in the tree

  • npm list express

    Check if express is installed and show its resolved version

  • npm list -g

    List all globally installed packages

  • npm list -g --depth=0

    List top-level globally installed packages only

  • npm list --all

    List the full dependency tree including all nested dependencies

  • npm list --link

    List only symlinked packages in node_modules

Audit & Security

  • npm audit

    Scan installed dependencies for known security vulnerabilities

  • npm audit --json

    Output vulnerability audit results as JSON

  • npm audit --production

    Audit only production dependencies for vulnerabilities

  • npm audit --audit-level=critical

    Exit with error only if critical severity vulnerabilities are found

  • npm audit --audit-level=high

    Exit with error if high or critical severity vulnerabilities are found

  • npm audit --audit-level=moderate

    Exit with error if moderate or higher severity vulnerabilities are found

  • npm audit fix

    Automatically fix vulnerabilities by updating affected packages

  • npm audit fix --force

    Force fix vulnerabilities even if it requires breaking semver changes

  • npm audit fix --dry-run

    Simulate audit fixes without applying any changes

  • npm audit fix --package-lock-only

    Fix vulnerabilities in package-lock.json only without touching node_modules

Versioning

  • npm version patch

    Increment the patch version in package.json and create a git tag

  • npm version minor

    Increment the minor version in package.json and create a git tag

  • npm version major

    Increment the major version in package.json and create a git tag

  • npm version prepatch

    Increment to the next prepatch prerelease version

  • npm version preminor

    Increment to the next preminor prerelease version

  • npm version premajor

    Increment to the next premajor prerelease version

  • npm version prerelease

    Increment the prerelease number of the current version

  • npm version prerelease --preid=alpha

    Increment the prerelease version with a custom identifier like alpha

  • npm version 2.0.0

    Set an explicit version number in package.json

  • npm version patch --no-git-tag-version

    Increment the patch version without creating a git commit or tag

  • npm version patch -m "chore: release v%s"

    Increment patch version and use a custom git commit message

Cache

  • npm cache clean --force

    Clear the entire npm cache directory

  • npm cache verify

    Verify the integrity and consistency of the npm cache

  • npm cache ls

    List cached packages stored in the npm cache directory

Linking

  • npm link

    Create a global symlink for the current package for local development

  • npm link my-package

    Link a globally symlinked package into the current project

  • npm unlink my-package

    Remove a previously linked package from the current project

  • npm unlink

    Remove the global symlink created for the current package

Outdated & Doctor

  • npm outdated

    Check which installed packages have newer versions available

  • npm outdated --json

    Output outdated package information as JSON

  • npm outdated --depth=0

    Check outdated status for top-level packages only

  • npm outdated -g

    Check for outdated globally installed packages

  • npm doctor

    Run a set of environment checks to verify npm is configured correctly

Package.json Management

  • npm pkg get name

    Read the name field from the current package.json

  • npm pkg get version

    Read the version field from the current package.json

  • npm pkg get scripts

    Read all scripts defined in the current package.json

  • npm pkg set name="my-app"

    Set the name field in package.json

  • npm pkg set version="1.0.0"

    Set the version field in package.json

  • npm pkg set scripts.build="tsc"

    Add or update a script entry in package.json

  • npm pkg set engines.node=">=18.0.0"

    Set the minimum required Node.js version in package.json

  • npm pkg delete scripts.build

    Remove a specific key from package.json

CI & Environment

  • npm ci

    Install dependencies strictly from package-lock.json for reproducible CI builds

  • npm ci --production

    Install only production dependencies from package-lock.json

  • npm ci --ignore-scripts

    Install from lockfile without running lifecycle scripts

  • npm ci --silent

    Install from lockfile suppressing all output except errors

  • npm ci --prefer-offline

    Install from lockfile using cache where possible

Organization & Teams

  • npm org set my-org username developer

    Add a user to an npm organization with the developer role

  • npm org set my-org username admin

    Add a user to an npm organization with the admin role

  • npm org rm my-org username

    Remove a user from an npm organization

  • npm org ls my-org

    List all members of an npm organization

  • npm team create my-org:frontend

    Create a new team within an npm organization

  • npm team destroy my-org:frontend

    Delete a team from an npm organization

  • npm team add my-org:frontend username

    Add a user to a specific team within an organization

  • npm team rm my-org:frontend username

    Remove a user from a specific team within an organization

  • npm team ls my-org

    List all teams within an npm organization

  • npm team ls my-org:frontend

    List all members of a specific team within an organization

  • npm access public my-package

    Set a package's access level to public

  • npm access restricted my-package

    Set a package's access level to restricted (private)

  • npm access grant read-only my-org:frontend my-package

    Grant read-only access to a team for a specific package

  • npm access grant read-write my-org:frontend my-package

    Grant read-write access to a team for a specific package

  • npm access revoke my-org:frontend my-package

    Revoke a team's access to a specific package

  • npm access ls-packages my-org

    List all packages accessible to an organization

  • npm access ls-collaborators my-package

    List all collaborators with access to a specific package

Miscellaneous

  • npm root

    Print the path to the local node_modules directory

  • npm root -g

    Print the path to the global node_modules directory

  • npm bin

    Print the path to the local .bin executables directory

  • npm bin -g

    Print the path to the global bin executables directory

  • npm prefix

    Print the nearest parent directory containing a package.json

  • npm prefix -g

    Print the global npm prefix directory

  • npm rebuild

    Rebuild all native addons for the current Node.js version

  • npm rebuild bcrypt

    Rebuild a specific native addon package

  • npm dedupe

    Reduce duplication in the dependency tree by flattening shared packages

  • npm prune

    Remove packages from node_modules that are not listed in package.json

  • npm prune --production

    Remove devDependency packages not needed in production

  • npm shrinkwrap

    Lock down dependency versions by generating an npm-shrinkwrap.json file

  • npm fund

    Display funding information for installed packages

  • npm fund express

    Display funding information for a specific package

  • npm explain express

    Explain why a package is installed and which packages depend on it

  • npm explain express --json

    Output the dependency explanation for a package as JSON

  • npm completion

    Output a shell completion script for npm commands

  • npm help install

    Open the documentation page for the npm install command

  • npm help-search publish

    Search npm help documentation for pages related to a keyword

  • npm --version

    Display the currently installed version of npm