Init & Config
Interactively create a package.json file
$npm initCreate a package.json file with all defaults, skipping prompts
$npm init -yInitialize a scoped package interactively
$npm init --scope=@myorgSet default author name used during npm init
$npm set init-author-name "John Doe"Set default author email used during npm init
$npm set init-author-email "john@example.com"Set default license used during npm init
$npm set init-license "MIT"Set the default npm registry URL
$npm config set registry https://registry.npmjs.org/Get the currently configured npm registry URL
$npm config get registryRemove the registry config key, reverting to default
$npm config delete registryList all active npm configuration values
$npm config listList all npm config values in JSON format
$npm config list --jsonOpen the global .npmrc file in the default editor
$npm config editConfigure npm to save exact versions instead of semver ranges
$npm config set save-exact trueSet the default semver prefix used when saving dependencies
$npm config set save-prefix "~"Set an HTTP proxy for npm network requests
$npm config set proxy http://proxy.example.com:8080Set an HTTPS proxy for npm network requests
$npm config set https-proxy http://proxy.example.com:8080Set a custom directory for the npm cache
$npm config set cache /path/to/cacheInstall & Add Packages
Install all dependencies listed in package.json
$npm installInstall only production dependencies, skipping devDependencies
$npm install --productionInstall only devDependencies
$npm install --only=devInstall dependencies without updating package-lock.json
$npm install --frozen-lockfileInstall packages ignoring peer dependency conflicts
$npm install --legacy-peer-depsForce reinstall of all packages, bypassing cache and lock
$npm install --forceInstall packages without running any lifecycle scripts
$npm install --ignore-scriptsUse cached packages when available, falling back to network
$npm install --prefer-offlineForce network fetch even when cached packages are available
$npm install --prefer-onlineInstall the latest version of the express package as a dependency
$npm install expressInstall a specific version of the express package
$npm install express@4.18.2Install the latest tagged version of the express package
$npm install express@latestInstall express at the latest version satisfying the given semver range
$npm install express@^4.0.0Install express and explicitly add it to dependencies in package.json
$npm install express --saveInstall express and pin the exact version in package.json
$npm install express --save-exactInstall typescript as a development dependency
$npm install typescript --save-devInstall an exact version of typescript as a devDependency
$npm install typescript --save-dev --save-exactInstall lodash as an optional dependency
$npm install lodash --save-optionalInstall typescript globally on the system
$npm install -g typescriptUpdate npm itself to the latest version globally
$npm install -g npm@latestInstall multiple packages simultaneously as dependencies
$npm install react react-domInstall a scoped package as a devDependency
$npm install @types/node --save-devInstall a package directly from a GitHub repository URL
$npm install git+https://github.com/user/repo.gitInstall a package from a GitHub shorthand reference
$npm install github:user/repoInstall a package from a specific branch of a GitHub repository
$npm install github:user/repo#branchInstall a package from a local directory path
$npm install ./path/to/local-packageInstall a local package using the file: protocol
$npm install file:./packages/my-libInstall a package from a remote tarball URL
$npm install https://example.com/package.tgzInstall express without modifying package.json
$npm install --no-save expressSimulate installing express without making any actual changes
$npm install --dry-run expressInstall express with verbose output for debugging
$npm install --verbose expressUninstall & Remove Packages
Remove express from node_modules and package.json dependencies
$npm uninstall expressRemove express from node_modules and explicitly remove from dependencies
$npm uninstall express --saveRemove typescript from node_modules and devDependencies
$npm uninstall typescript --save-devRemove lodash from node_modules and optionalDependencies
$npm uninstall lodash --save-optionalRemove a globally installed package
$npm uninstall -g typescriptRemove express from node_modules without modifying package.json
$npm uninstall --no-save expressRemove multiple packages simultaneously
$npm uninstall react react-domUpdate Packages
Update all packages to the latest version within their semver range
$npm updateUpdate express to the latest version within its semver range
$npm update expressUpdate all packages and persist updated versions to package.json
$npm update --saveUpdate all globally installed packages
$npm update -gUpdate a specific globally installed package
$npm update -g typescriptUpdate packages up to 2 levels deep in the dependency tree
$npm update --depth 2Scripts & Execution
Execute the build script defined in package.json scripts
$npm run buildExecute the dev script defined in package.json scripts
$npm run devExecute the test script defined in package.json scripts
$npm run testExecute the lint script defined in package.json scripts
$npm run lintExecute the format script defined in package.json scripts
$npm run formatExecute the start script defined in package.json scripts
$npm run startRun the start script shorthand (no run keyword needed)
$npm startRun the test script shorthand (no run keyword needed)
$npm testPass additional arguments to a script after the double-dash separator
$npm run build -- --watchRun the build script only if it exists, without erroring if absent
$npm run build --if-presentList environment variables available to scripts at runtime
$npm run envExecute a locally installed binary from node_modules/.bin
$npm exec tscExecute a local binary with arguments using the double-dash separator
$npm exec -- tsc --initRun a package binary without installing it permanently
$npx create-react-app my-appRun a package binary, auto-confirming installation prompts
$npx --yes create-next-app my-appRun a local binary only, without fetching from registry if missing
$npx --no-install tscSpecify a package to install and then run its binary
$npx -p typescript tsc --initWorkspaces
Install dependencies for all workspaces in a monorepo
$npm install --workspacesInstall dependencies for a specific workspace by path
$npm install --workspace=packages/appRun the build script across all workspaces
$npm run build --workspacesRun the build script in a specific workspace
$npm run build --workspace=packages/appRun test script across all workspaces only where it exists
$npm run test --workspaces --if-presentInstall a package into a specific workspace
$npm install lodash --workspace=packages/appExecute a binary in the context of a specific workspace
$npm exec --workspace=packages/app -- tscGet the name field from package.json for all workspaces
$npm pkg get name --workspacesPublish & Registry
Publish the current package to the npm registry
$npm publishPublish a scoped package publicly to the npm registry
$npm publish --access publicPublish a package as restricted (private)
$npm publish --access restrictedPublish the package under a custom dist-tag instead of latest
$npm publish --tag betaSimulate publishing without uploading anything to the registry
$npm publish --dry-runPublish using a one-time password for 2FA-enabled accounts
$npm publish --otp 123456Remove a specific version of a package from the registry
$npm unpublish my-package@1.0.0Force-remove an entire package from the registry
$npm unpublish my-package --forceMark a specific package version as deprecated with a message
$npm deprecate my-package@1.0.0 "Use v2 instead"Add a dist-tag pointing to a specific version
$npm dist-tag add my-package@1.0.0 stableRemove a dist-tag from a package
$npm dist-tag rm my-package betaList all dist-tags for a package
$npm dist-tag ls my-packageCreate a .tgz tarball of the current package without publishing
$npm packList files that would be included in the tarball without creating it
$npm pack --dry-runAuthentication
Log in to the npm registry interactively
$npm loginLog in to a specific npm registry
$npm login --registry https://registry.npmjs.org/Associate a scope with a specific registry and log in
$npm login --scope=@myorgLog out from the npm registry, removing auth tokens
$npm logoutLog out from a specific registry
$npm logout --registry https://registry.npmjs.org/Display the currently authenticated npm username
$npm whoamiDisplay the authenticated username for a specific registry
$npm whoami --registry https://registry.npmjs.org/List all authentication tokens for the current account
$npm token listCreate a new authentication token
$npm token createCreate a read-only authentication token
$npm token create --read-onlyCreate a token restricted to a specific CIDR IP range
$npm token create --cidr 192.168.1.0/24Revoke a specific authentication token by its ID or value
$npm token revoke abc123Info & Search
Display metadata for the express package from the registry
$npm info expressDisplay only the latest version of express
$npm info express versionList all published versions of express
$npm info express versionsDisplay the dependencies of the latest express version
$npm info express dependenciesDisplay full package metadata in JSON format
$npm info express --jsonAlias for npm info — display registry metadata for a package
$npm view expressShow dependencies for a specific version of express
$npm view express@4.18.2 dependenciesSearch the npm registry for packages matching a keyword
$npm search lodashSearch the npm registry and return results as JSON
$npm search lodash --jsonSearch npm with a limit on the number of results returned
$npm search --searchlimit 20 lodashOpen the documentation homepage for the express package in a browser
$npm docs expressOpen the repository URL for the express package in a browser
$npm repo expressOpen the issue tracker for the express package in a browser
$npm bugs expressOpen the homepage of the express package in a browser
$npm home expressListing & Dependency Tree
List installed packages and their dependency tree in the current project
$npm listList only top-level installed packages without sub-dependencies
$npm list --depth=0List installed packages up to one level of sub-dependencies
$npm list --depth=1Output the installed dependency tree in JSON format
$npm list --jsonList only production dependencies in the tree
$npm list --productionList only development dependencies in the tree
$npm list --devCheck if express is installed and show its resolved version
$npm list expressList all globally installed packages
$npm list -gList top-level globally installed packages only
$npm list -g --depth=0List the full dependency tree including all nested dependencies
$npm list --allList only symlinked packages in node_modules
$npm list --linkAudit & Security
Scan installed dependencies for known security vulnerabilities
$npm auditOutput vulnerability audit results as JSON
$npm audit --jsonAudit only production dependencies for vulnerabilities
$npm audit --productionExit with error only if critical severity vulnerabilities are found
$npm audit --audit-level=criticalExit with error if high or critical severity vulnerabilities are found
$npm audit --audit-level=highExit with error if moderate or higher severity vulnerabilities are found
$npm audit --audit-level=moderateAutomatically fix vulnerabilities by updating affected packages
$npm audit fixForce fix vulnerabilities even if it requires breaking semver changes
$npm audit fix --forceSimulate audit fixes without applying any changes
$npm audit fix --dry-runFix vulnerabilities in package-lock.json only without touching node_modules
$npm audit fix --package-lock-onlyVersioning
Increment the patch version in package.json and create a git tag
$npm version patchIncrement the minor version in package.json and create a git tag
$npm version minorIncrement the major version in package.json and create a git tag
$npm version majorIncrement to the next prepatch prerelease version
$npm version prepatchIncrement to the next preminor prerelease version
$npm version preminorIncrement to the next premajor prerelease version
$npm version premajorIncrement the prerelease number of the current version
$npm version prereleaseIncrement the prerelease version with a custom identifier like alpha
$npm version prerelease --preid=alphaSet an explicit version number in package.json
$npm version 2.0.0Increment the patch version without creating a git commit or tag
$npm version patch --no-git-tag-versionIncrement patch version and use a custom git commit message
$npm version patch -m "chore: release v%s"Cache
Clear the entire npm cache directory
$npm cache clean --forceVerify the integrity and consistency of the npm cache
$npm cache verifyList cached packages stored in the npm cache directory
$npm cache lsLinking
Create a global symlink for the current package for local development
$npm linkLink a globally symlinked package into the current project
$npm link my-packageRemove a previously linked package from the current project
$npm unlink my-packageRemove the global symlink created for the current package
$npm unlinkOutdated & Doctor
Check which installed packages have newer versions available
$npm outdatedOutput outdated package information as JSON
$npm outdated --jsonCheck outdated status for top-level packages only
$npm outdated --depth=0Check for outdated globally installed packages
$npm outdated -gRun a set of environment checks to verify npm is configured correctly
$npm doctorPackage.json Management
Read the name field from the current package.json
$npm pkg get nameRead the version field from the current package.json
$npm pkg get versionRead all scripts defined in the current package.json
$npm pkg get scriptsSet the name field in package.json
$npm pkg set name="my-app"Set the version field in package.json
$npm pkg set version="1.0.0"Add or update a script entry in package.json
$npm pkg set scripts.build="tsc"Set the minimum required Node.js version in package.json
$npm pkg set engines.node=">=18.0.0"Remove a specific key from package.json
$npm pkg delete scripts.buildCI & Environment
Install dependencies strictly from package-lock.json for reproducible CI builds
$npm ciInstall only production dependencies from package-lock.json
$npm ci --productionInstall from lockfile without running lifecycle scripts
$npm ci --ignore-scriptsInstall from lockfile suppressing all output except errors
$npm ci --silentInstall from lockfile using cache where possible
$npm ci --prefer-offlineOrganization & Teams
Add a user to an npm organization with the developer role
$npm org set my-org username developerAdd a user to an npm organization with the admin role
$npm org set my-org username adminRemove a user from an npm organization
$npm org rm my-org usernameList all members of an npm organization
$npm org ls my-orgCreate a new team within an npm organization
$npm team create my-org:frontendDelete a team from an npm organization
$npm team destroy my-org:frontendAdd a user to a specific team within an organization
$npm team add my-org:frontend usernameRemove a user from a specific team within an organization
$npm team rm my-org:frontend usernameList all teams within an npm organization
$npm team ls my-orgList all members of a specific team within an organization
$npm team ls my-org:frontendSet a package's access level to public
$npm access public my-packageSet a package's access level to restricted (private)
$npm access restricted my-packageGrant read-only access to a team for a specific package
$npm access grant read-only my-org:frontend my-packageGrant read-write access to a team for a specific package
$npm access grant read-write my-org:frontend my-packageRevoke a team's access to a specific package
$npm access revoke my-org:frontend my-packageList all packages accessible to an organization
$npm access ls-packages my-orgList all collaborators with access to a specific package
$npm access ls-collaborators my-packageMiscellaneous
Print the path to the local node_modules directory
$npm rootPrint the path to the global node_modules directory
$npm root -gPrint the path to the local .bin executables directory
$npm binPrint the path to the global bin executables directory
$npm bin -gPrint the nearest parent directory containing a package.json
$npm prefixPrint the global npm prefix directory
$npm prefix -gRebuild all native addons for the current Node.js version
$npm rebuildRebuild a specific native addon package
$npm rebuild bcryptReduce duplication in the dependency tree by flattening shared packages
$npm dedupeRemove packages from node_modules that are not listed in package.json
$npm pruneRemove devDependency packages not needed in production
$npm prune --productionLock down dependency versions by generating an npm-shrinkwrap.json file
$npm shrinkwrapDisplay funding information for installed packages
$npm fundDisplay funding information for a specific package
$npm fund expressExplain why a package is installed and which packages depend on it
$npm explain expressOutput the dependency explanation for a package as JSON
$npm explain express --jsonOutput a shell completion script for npm commands
$npm completionOpen the documentation page for the npm install command
$npm help installSearch npm help documentation for pages related to a keyword
$npm help-search publishDisplay the currently installed version of npm
$npm --version