npm
npm 10+Quick reference for everyday npm CLI commands: init / install / add / remove / update / scripts / run / publish / audit, plus lockfile, registry, and cache management — with common options and practical examples.
34 commands
Project init
npm initWalk through `package.json` creation interactively, prompting for name / version / description / entry point / etc.
-y accept all defaults; --init.author 'Name <e@x>' override defaults
npm init -ynpm init -yGenerate a `package.json` immediately with sensible defaults (`name` from directory, `version` 1.0.0, etc.) — the modern starting point.
npm init -y && cat package.jsonInstall
npm installInstall every dependency listed in `package.json`, refreshing `node_modules` and `package-lock.json`. Skips dev deps if `NODE_ENV=production`.
--save-exact / -E pin exact versions; --legacy-peer-deps; --force; --no-audit; --prefer-offline
npm installnpm ciClean install strictly from `package-lock.json`. Faster than `npm install`, deletes `node_modules` first, and refuses to mutate the lockfile — the right call for CI.
--omit=dev skip devDependencies; --prefer-offline
npm ci --omit=devAdd dependency
npm install <pkg>Add a runtime dependency (default `dependencies`). Records the resolved version in `package-lock.json` and writes `package.json`.
<pkg>@<version-range>; --save-dev / -D; --save-exact / -E; --save-optional / -O; --save-prod / -P
npm install lodash && npm install eslint@^9 --save-devnpm install <pkg>@<version>Install a specific version range (semver): exact `1.2.3`, tilde `~1.2.3`, caret `^1.2.3`, or tag like `latest` / `next` / `beta`.
npm install [email protected] && npm install next@latestnpm install -D <pkg>Add to `devDependencies` — tools only needed at build / test time (TypeScript, Jest, ESLint, Prettier).
npm install -D typescript @types/node vitestnpm install -g <pkg>Install a package globally so its binary is on `PATH` for every project (TypeScript, tsx, create-react-app, http-server).
npm install -g typescript tsx pnpmRemove
npm uninstall <pkg>Remove a package from `node_modules` and `package.json`.
-D remove from devDependencies; -g remove a global; --save false to skip manifest edit (rare)
npm uninstall lodash && npm uninstall -D @types/nodeUpdate
npm updateUpgrade every dependency within the range allowed by `package.json` semver specs, refreshing `package-lock.json` accordingly.
--save false to skip manifest write; --workspace update inside workspaces
npm updatenpm update <pkg>Update one package to the latest version that satisfies its current semver range.
npm update eslintnpm install <pkg>@latestUpgrade a single package to the newest release (bypasses the semver range and rewrites the range to `^<new-version>`).
npm install typescript@latest && npm install -D vitest@latestRun script
npm run <script>Execute a script defined under the `scripts` section of `package.json`. `npm test`, `npm start`, `npm stop`, `npm restart` are shorthand for `npm run X`.
-- silent suppress npm log noise; --if-present don't error if missing; -- <args> forward remaining args to the script
npm run build -- --mode productionnpm run <script> -- <args>Pass extra CLI arguments to the underlying script. Everything after `--` is forwarded untouched.
npm run lint -- --fix src/npm exec -- <command>Run a command from a local or `npx`-cached package. Replaces the deprecated `npx <command>` direct call.
npm exec -- create-react-app my-appInspect
npm lsPrint the dependency tree of the current project (top-level + transitive). Useful for finding duplicate copies of a package.
--all; --depth=N limit depth; --json output JSON; -g list globals
npm ls --depth=0 && npm ls reactnpm outdatedShow a table of every dep whose installed version is older than the latest version allowed by the manifest's range.
--long verbose; --json output JSON
npm outdatednpm view <pkg>Display registry metadata for a package — versions, dist-tags, dependencies, maintainers, repository URL, readme excerpt.
versions; time; dist-tags; repository.url
npm view lodash versions && npm view react dist-tagsLockfile
npm shrinkwrapGenerate a standalone `npm-shrinkwrap.json` (same format as `package-lock.json`) for apps that need reproducible installs even when shipped without a lockfile.
npm shrinkwrapRegistry
npm config get registryPrint the currently-active registry URL. Default is `https://registry.npmjs.org/`.
npm config get registrynpm config set registry <url>Point npm at a private / cached registry (GitHub Packages, Verdaccio, China mirrors). Write to `~/.npmrc` or project `.npmrc`.
npm config set registry https://registry.npmmirror.com/npm loginAuthenticate against the configured registry and store a token in `~/.npmrc`. Required before `npm publish`.
--registry=<url> log in to a different registry; --scope=<scope> restrict token
npm login --registry=https://registry.npmjs.org/Publish
npm publishUpload the current package to the configured registry. Requires `name` (and usually `version`, `repository`) in `package.json` and a logged-in user with publish rights.
--access public|restricted (scoped packages); --dry-run; --tag <tag> ship under a dist-tag
npm publish --access public --tag betanpm unpublish <pkg>@<version>Remove a specific version from the registry. **Strongly discouraged within 72 hours of publish** — npm supports it but discourages.
npm unpublish [email protected]npm deprecate <pkg>@<version> '<msg>'Mark a version as deprecated with a message that npm prints on install. The right way to point users at a fix without deleting history.
npm deprecate [email protected] 'use 1.2.4+ — security fix'Audit
npm auditRun a security audit against the installed dependency tree, fetching advisories from the npm registry.
--json; --omit=dev skip dev deps; --audit-level=low|moderate|high|critical
npm audit --omit=devnpm audit fixAuto-upgrade packages to the closest non-breaking version that resolves the advisory. Use `npm audit fix --force` only when you accept semver-major jumps.
--force; --dry-run
npm audit fixCache
npm cache clean --forceWipe the global npm cache (`~/.npm` on POSIX). Use after switching registries or chasing weird install errors.
npm cache clean --forcenpm cache verifyValidate the integrity of cached tarballs without deleting. Safe to run any time.
npm cache verifyWorkspaces
npm install -w <workspace>Install a package into a single named workspace within a monorepo (defined under `workspaces` in `package.json`).
npm install lodash -w @myorg/webnpm run <script> -wsRun a script in every workspace of the monorepo. `-w <name>` runs only one workspace.
--if-present don't error if missing
npm run build -ws && npm test -w @myorg/apiMisc
npm doctorRun environment diagnostics (Node version, registry reachability, cache health, Git presence) — handy when troubleshooting.
npm doctornpm fundPrint the funding links for the current project's direct dependencies (used by maintainers to sponsor OSS).
npm fundnpm pkg set <key>=<value>Mutate fields inside `package.json` from the CLI without opening an editor. Useful in scripts / hooks.
npm pkg set scripts.lint='eslint .' && npm pkg get versionRelated command cheatsheets
volta
Quick reference for everyday Volta commands: install Node / npm / Yarn / pnpm toolchains, pin per-project versions, manage global packages, and troubleshoot Volta itself — with common options and practical examples.
25 commands
Volta 1.x
yarn
Quick reference for everyday Yarn CLI commands (both Yarn Classic 1.x and Yarn Berry 2/3/4): install / add / remove / run / workspaces, lockfile, Plug'n'Play, and Berry configuration — with common options and practical examples.
33 commands
Yarn 1.x (classic) / Yarn 4 (berry)
pnpm
Quick reference for pnpm: install / add / remove / update, scripts, workspaces, store & cache and config — focused on the GitHub-site pnpm repo workflow, with options and practical examples.
31 commands
pnpm 9+
npx
Quick reference for npx commands: run one-off package binaries, scaffold projects, manage the npx cache, pin versions, and avoid pitfalls with interactive CLIs — with common options and practical examples.
25 commands
npx 10+ (shipped with npm)
vite
Quick reference for Vite CLI commands: dev server, build, preview, dependency pre-bundling, plugin management, environment variables, and project inspection — with common options and practical examples.
30 commands
Vite 5+
Trademark & Use Notice
These command-line tool cheatsheets are open community references. The names, logos, and trademarks of the tools referenced here (such as Git™, Docker™, Kubernetes®, kubectl, PostgreSQL®, MySQL®, Redis™, MongoDB®, Linux™, PowerShell™, Vim™, and others) are the property of their respective owners and are used here solely for identification and reference purposes.
All content in these cheatsheets is independently authored as a simplified, self-contained reference. It is not affiliated with, endorsed by, or sourced from any official documentation. Command listings, flag descriptions, and examples are original simplifications; for authoritative information please consult the official documentation of each tool.
Command syntax and option flags may differ across tool versions. The version tags shown reflect stable releases; behavior may differ in other versions. This cheatsheet does not imply any preference or recommendation by the trademark holders.
If a trademark or copyright owner believes that any content on this site infringes their rights, please send an email to [email protected]. Upon receiving valid proof of rights, we will modify or remove the relevant content within a reasonable period.
This website assumes no legal liability for any direct or indirect losses arising from the use of information presented on these pages.
About npm
npm is the default package manager for Node.js, originally written by Isaac Z. Schlueter in 2010 as a standalone tool, and bundled with Node since Node.js 0.6.3 in 2011. The name stood for `Node Package Manager` but the team has officially stopped treating it as an acronym since 2014. The current stable line is npm 10, which ships alongside Node 20+. npm talks to a registry (the default `registry.npmjs.org`, a public CouchDB hosted by GitHub since 2020), reads / writes `package.json` + `package-lock.json`, and supports both local installs (`node_modules` in your project) and global installs (added to PATH). npm 7+ introduced workspaces for monorepos; npm 9+ ships with `npx` built in and a strict peer-dependency engine. Most npm commands accept `-D` (dev), `-E` (exact), `-g` (global), `--save-prod`, and a `--prefix` flag for non-standard install directories. npm never uploads your code — it only writes to local files and the registry. Anonymous download metrics are aggregated by the npm registry but no project contents are sent.
Cheatsheet version 1.0.0