← All cheatsheets

Build

npm / pnpm / yarn — comparison + when to use which

npm, pnpm and yarn side by side: install, run scripts, run one-off binaries, frozen CI installs, lockfiles, and when to use which.

Install dependencies

| Action | npm | pnpm | yarn |

|---|---|---|---|

| Install all | npm install | pnpm install | yarn |

| Add prod | npm i pkg | pnpm add pkg | yarn add pkg |

| Add dev | npm i -D pkg | pnpm add -D pkg | yarn add -D pkg |

| Add global | npm i -g pkg | pnpm add -g pkg | yarn global add pkg |

| Remove | npm un pkg | pnpm rm pkg | yarn remove pkg |

| Upgrade | npm update pkg | pnpm update pkg | yarn upgrade pkg |

Run scripts

npm run dev / pnpm dev / yarn dev

(pnpm + yarn don't require run for non-reserved names.)

Execute one-off binary (without installing)

npx pkg arg / pnpm dlx pkg arg / yarn dlx pkg arg

Frozen / lockfile-strict installs (for CI)

npm ci (uses package-lock.json, no updates)

pnpm install --frozen-lockfile

yarn install --frozen-lockfile (yarn classic) / yarn install --immutable (yarn berry)

Lockfile names

  • npm → package-lock.json
  • pnpm → pnpm-lock.yaml
  • yarn classic → yarn.lock
  • yarn berry → yarn.lock + .yarn/cache

When to use which

  • pnpm: best for monorepos + disk efficiency (content-addressable store). Fastest install. Recommended default in 2026.
  • npm: ships with Node, no extra install. Use if you want zero ceremony.
  • yarn berry (v2+): best for workspaces + PnP if you want zero node_modules. Newer ecosystem support varies.

Monorepo

  • pnpm: pnpm-workspace.yaml + run pnpm -F <pkg> ...
  • yarn: workspaces in root package.json
  • npm: also supports workspaces since v7