NPM commands
Node Package Manager — the default package manager for Node.js
Init & Config
npm initInteractively create a package.json file
npm init -yCreate a package.json file with all defaults, skipping prompts
npm init --scope=@myorgInitialize 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 registryGet the currently configured npm registry URL
npm config delete registryRemove the registry config key, reverting to default
npm config listList all active npm configuration values
npm config list --jsonList all npm config values in JSON format
npm config editOpen the global .npmrc file in the default editor
npm config set save-exact trueConfigure 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:8080Set an HTTP proxy for npm network requests
npm config set https-proxy http://proxy.example.com:8080Set an HTTPS proxy for npm network requests
npm config set cache /path/to/cacheSet a custom directory for the npm cache
Install & Add Packages
npm installInstall all dependencies listed in package.json
npm install --productionInstall only production dependencies, skipping devDependencies
npm install --only=devInstall only devDependencies
npm install --frozen-lockfileInstall dependencies without updating package-lock.json
npm install --legacy-peer-depsInstall packages ignoring peer dependency conflicts
npm install --forceForce reinstall of all packages, bypassing cache and lock
npm install --ignore-scriptsInstall packages without running any lifecycle scripts
npm install --prefer-offlineUse cached packages when available, falling back to network
npm install --prefer-onlineForce network fetch even when cached packages are available
npm install expressInstall the latest version of the express package as a dependency
npm install express@4.18.2Install a specific version of the express package
npm install express@latestInstall the latest tagged version of the express package
npm install express@^4.0.0Install express at the latest version satisfying the given semver range
npm install express --saveInstall express and explicitly add it to dependencies in package.json
npm install express --save-exactInstall express and pin the exact version in package.json
npm install typescript --save-devInstall typescript as a development dependency
npm install typescript --save-dev --save-exactInstall an exact version of typescript as a devDependency
npm install lodash --save-optionalInstall lodash as an optional dependency
npm install -g typescriptInstall typescript globally on the system
npm install -g npm@latestUpdate npm itself to the latest version globally
npm install react react-domInstall multiple packages simultaneously as dependencies
npm install @types/node --save-devInstall a scoped package as a devDependency
npm install git+https://github.com/user/repo.gitInstall a package directly from a GitHub repository URL
npm install github:user/repoInstall a package from a GitHub shorthand reference
npm install github:user/repo#branchInstall a package from a specific branch of a GitHub repository
npm install ./path/to/local-packageInstall a package from a local directory path
npm install file:./packages/my-libInstall a local package using the file: protocol
npm install https://example.com/package.tgzInstall a package from a remote tarball URL
npm install --no-save expressInstall express without modifying package.json
npm install --dry-run expressSimulate installing express without making any actual changes
npm install --verbose expressInstall express with verbose output for debugging
Uninstall & Remove Packages
npm uninstall expressRemove express from node_modules and package.json dependencies
npm uninstall express --saveRemove express from node_modules and explicitly remove from dependencies
npm uninstall typescript --save-devRemove typescript from node_modules and devDependencies
npm uninstall lodash --save-optionalRemove lodash from node_modules and optionalDependencies
npm uninstall -g typescriptRemove a globally installed package
npm uninstall --no-save expressRemove express from node_modules without modifying package.json
npm uninstall react react-domRemove multiple packages simultaneously
Update Packages
npm updateUpdate all packages to the latest version within their semver range
npm update expressUpdate express to the latest version within its semver range
npm update --saveUpdate all packages and persist updated versions to package.json
npm update -gUpdate all globally installed packages
npm update -g typescriptUpdate a specific globally installed package
npm update --depth 2Update packages up to 2 levels deep in the dependency tree
Scripts & Execution
npm run buildExecute the build script defined in package.json scripts
npm run devExecute the dev script defined in package.json scripts
npm run testExecute the test script defined in package.json scripts
npm run lintExecute the lint script defined in package.json scripts
npm run formatExecute the format script defined in package.json scripts
npm run startExecute the start script defined in package.json scripts
npm startRun the start script shorthand (no run keyword needed)
npm testRun the test script shorthand (no run keyword needed)
npm run build -- --watchPass additional arguments to a script after the double-dash separator
npm run build --if-presentRun the build script only if it exists, without erroring if absent
npm run envList environment variables available to scripts at runtime
npm exec tscExecute a locally installed binary from node_modules/.bin
npm exec -- tsc --initExecute a local binary with arguments using the double-dash separator
npx create-react-app my-appRun a package binary without installing it permanently
npx --yes create-next-app my-appRun a package binary, auto-confirming installation prompts
npx --no-install tscRun a local binary only, without fetching from registry if missing
npx -p typescript tsc --initSpecify a package to install and then run its binary
Workspaces
npm install --workspacesInstall dependencies for all workspaces in a monorepo
npm install --workspace=packages/appInstall dependencies for a specific workspace by path
npm run build --workspacesRun the build script across all workspaces
npm run build --workspace=packages/appRun the build script in a specific workspace
npm run test --workspaces --if-presentRun test script across all workspaces only where it exists
npm install lodash --workspace=packages/appInstall a package into a specific workspace
npm exec --workspace=packages/app -- tscExecute a binary in the context of a specific workspace
npm pkg get name --workspacesGet the name field from package.json for all workspaces
Publish & Registry
npm publishPublish the current package to the npm registry
npm publish --access publicPublish a scoped package publicly to the npm registry
npm publish --access restrictedPublish a package as restricted (private)
npm publish --tag betaPublish the package under a custom dist-tag instead of latest
npm publish --dry-runSimulate publishing without uploading anything to the registry
npm publish --otp 123456Publish using a one-time password for 2FA-enabled accounts
npm unpublish my-package@1.0.0Remove a specific version of a package from the registry
npm unpublish my-package --forceForce-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 stableAdd a dist-tag pointing to a specific version
npm dist-tag rm my-package betaRemove a dist-tag from a package
npm dist-tag ls my-packageList all dist-tags for a package
npm packCreate a .tgz tarball of the current package without publishing
npm pack --dry-runList files that would be included in the tarball without creating it
Authentication
npm loginLog in to the npm registry interactively
npm login --registry https://registry.npmjs.org/Log in to a specific npm registry
npm login --scope=@myorgAssociate a scope with a specific registry and log in
npm logoutLog out from the npm registry, removing auth tokens
npm logout --registry https://registry.npmjs.org/Log out from a specific registry
npm whoamiDisplay the currently authenticated npm username
npm whoami --registry https://registry.npmjs.org/Display the authenticated username for a specific registry
npm token listList all authentication tokens for the current account
npm token createCreate a new authentication token
npm token create --read-onlyCreate a read-only authentication token
npm token create --cidr 192.168.1.0/24Create a token restricted to a specific CIDR IP range
npm token revoke abc123Revoke a specific authentication token by its ID or value
Info & Search
npm info expressDisplay metadata for the express package from the registry
npm info express versionDisplay only the latest version of express
npm info express versionsList all published versions of express
npm info express dependenciesDisplay the dependencies of the latest express version
npm info express --jsonDisplay full package metadata in JSON format
npm view expressAlias for npm info — display registry metadata for a package
npm view express@4.18.2 dependenciesShow dependencies for a specific version of express
npm search lodashSearch the npm registry for packages matching a keyword
npm search lodash --jsonSearch the npm registry and return results as JSON
npm search --searchlimit 20 lodashSearch npm with a limit on the number of results returned
npm docs expressOpen the documentation homepage for the express package in a browser
npm repo expressOpen the repository URL for the express package in a browser
npm bugs expressOpen the issue tracker for the express package in a browser
npm home expressOpen the homepage of the express package in a browser
Listing & Dependency Tree
npm listList installed packages and their dependency tree in the current project
npm list --depth=0List only top-level installed packages without sub-dependencies
npm list --depth=1List installed packages up to one level of sub-dependencies
npm list --jsonOutput the installed dependency tree in JSON format
npm list --productionList only production dependencies in the tree
npm list --devList only development dependencies in the tree
npm list expressCheck if express is installed and show its resolved version
npm list -gList all globally installed packages
npm list -g --depth=0List top-level globally installed packages only
npm list --allList the full dependency tree including all nested dependencies
npm list --linkList only symlinked packages in node_modules
Audit & Security
npm auditScan installed dependencies for known security vulnerabilities
npm audit --jsonOutput vulnerability audit results as JSON
npm audit --productionAudit only production dependencies for vulnerabilities
npm audit --audit-level=criticalExit with error only if critical severity vulnerabilities are found
npm audit --audit-level=highExit with error if high or critical severity vulnerabilities are found
npm audit --audit-level=moderateExit with error if moderate or higher severity vulnerabilities are found
npm audit fixAutomatically fix vulnerabilities by updating affected packages
npm audit fix --forceForce fix vulnerabilities even if it requires breaking semver changes
npm audit fix --dry-runSimulate audit fixes without applying any changes
npm audit fix --package-lock-onlyFix vulnerabilities in package-lock.json only without touching node_modules
Versioning
npm version patchIncrement the patch version in package.json and create a git tag
npm version minorIncrement the minor version in package.json and create a git tag
npm version majorIncrement the major version in package.json and create a git tag
npm version prepatchIncrement to the next prepatch prerelease version
npm version preminorIncrement to the next preminor prerelease version
npm version premajorIncrement to the next premajor prerelease version
npm version prereleaseIncrement the prerelease number of the current version
npm version prerelease --preid=alphaIncrement the prerelease version with a custom identifier like alpha
npm version 2.0.0Set an explicit version number in package.json
npm version patch --no-git-tag-versionIncrement 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 --forceClear the entire npm cache directory
npm cache verifyVerify the integrity and consistency of the npm cache
npm cache lsList cached packages stored in the npm cache directory
Linking
npm linkCreate a global symlink for the current package for local development
npm link my-packageLink a globally symlinked package into the current project
npm unlink my-packageRemove a previously linked package from the current project
npm unlinkRemove the global symlink created for the current package
Outdated & Doctor
npm outdatedCheck which installed packages have newer versions available
npm outdated --jsonOutput outdated package information as JSON
npm outdated --depth=0Check outdated status for top-level packages only
npm outdated -gCheck for outdated globally installed packages
npm doctorRun a set of environment checks to verify npm is configured correctly
Package.json Management
npm pkg get nameRead the name field from the current package.json
npm pkg get versionRead the version field from the current package.json
npm pkg get scriptsRead 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.buildRemove a specific key from package.json
CI & Environment
npm ciInstall dependencies strictly from package-lock.json for reproducible CI builds
npm ci --productionInstall only production dependencies from package-lock.json
npm ci --ignore-scriptsInstall from lockfile without running lifecycle scripts
npm ci --silentInstall from lockfile suppressing all output except errors
npm ci --prefer-offlineInstall from lockfile using cache where possible
Organization & Teams
npm org set my-org username developerAdd a user to an npm organization with the developer role
npm org set my-org username adminAdd a user to an npm organization with the admin role
npm org rm my-org usernameRemove a user from an npm organization
npm org ls my-orgList all members of an npm organization
npm team create my-org:frontendCreate a new team within an npm organization
npm team destroy my-org:frontendDelete a team from an npm organization
npm team add my-org:frontend usernameAdd a user to a specific team within an organization
npm team rm my-org:frontend usernameRemove a user from a specific team within an organization
npm team ls my-orgList all teams within an npm organization
npm team ls my-org:frontendList all members of a specific team within an organization
npm access public my-packageSet a package's access level to public
npm access restricted my-packageSet a package's access level to restricted (private)
npm access grant read-only my-org:frontend my-packageGrant read-only access to a team for a specific package
npm access grant read-write my-org:frontend my-packageGrant read-write access to a team for a specific package
npm access revoke my-org:frontend my-packageRevoke a team's access to a specific package
npm access ls-packages my-orgList all packages accessible to an organization
npm access ls-collaborators my-packageList all collaborators with access to a specific package
Miscellaneous
npm rootPrint the path to the local node_modules directory
npm root -gPrint the path to the global node_modules directory
npm binPrint the path to the local .bin executables directory
npm bin -gPrint the path to the global bin executables directory
npm prefixPrint the nearest parent directory containing a package.json
npm prefix -gPrint the global npm prefix directory
npm rebuildRebuild all native addons for the current Node.js version
npm rebuild bcryptRebuild a specific native addon package
npm dedupeReduce duplication in the dependency tree by flattening shared packages
npm pruneRemove packages from node_modules that are not listed in package.json
npm prune --productionRemove devDependency packages not needed in production
npm shrinkwrapLock down dependency versions by generating an npm-shrinkwrap.json file
npm fundDisplay funding information for installed packages
npm fund expressDisplay funding information for a specific package
npm explain expressExplain why a package is installed and which packages depend on it
npm explain express --jsonOutput the dependency explanation for a package as JSON
npm completionOutput a shell completion script for npm commands
npm help installOpen the documentation page for the npm install command
npm help-search publishSearch npm help documentation for pages related to a keyword
npm --versionDisplay the currently installed version of npm