NPM vs PNPM cheatsheet

Comparison of the most useful npm vs pnpm scripts/commands, side-by-side, including workspace-related ones. Useful for daily use, monorepos, and publishing workflows.

LinkIcon⚙️ Setup & Installation

Tasknpmpnpm
Init a projectnpm initpnpm init
Init with defaultsnpm init -ypnpm init -y
Install depsnpm installpnpm install
Install specific pkgnpm install lodashpnpm add lodash
Install dev depnpm install -D typescriptpnpm add -D typescript
Install globallynpm install -g nodemonpnpm add -g nodemon
Remove packagenpm uninstall lodashpnpm remove lodash
Update packagesnpm updatepnpm update
Install exact versionnpm install react@18.2.0pnpm add react@18.2.0

LinkIcon📦 Lockfiles & Node Modules

Tasknpmpnpm
Lockfilepackage-lock.jsonpnpm-lock.yaml
Node modulesflat structuresymlinked, content-addressed
Reinstall from lockfilenpm cipnpm install --frozen-lockfile
Clear cachenpm cache clean --forcepnpm store prune
Prune unused depsnpm prunepnpm prune

LinkIcon🧪 Scripts & Running

Tasknpmpnpm
Run scriptnpm run devpnpm dev
Run script (with args)npm run build -- --watchpnpm build --watch
Run bin from depsnpx eslint .pnpm exec eslint .
Run multiple scriptsnpm run dev1 & npm run dev2pnpm -r run dev
Open interactive shell(no equivalent)pnpm dlx

LinkIcon🧱 Workspaces (Monorepos)

Tasknpmpnpm
Enable workspacesAdd "workspaces" to package.jsonSame, plus pnpm-workspace.yaml
Run script in all packagesnpm run build --ws (v8+)pnpm -r run build
Run script in one package(cd to pkg dir)pnpm --filter pkg-name run build
Install in one workspace package(cd to pkg dir)pnpm add lodash --filter pkg-name
Recursive installnpm installpnpm install
List workspace packagesnpm ls --workspacespnpm list -r

LinkIcon📦 Publishing

Tasknpmpnpm
Login to registrynpm loginpnpm login
Publish a packagenpm publishpnpm publish
Publish with accessnpm publish --access publicpnpm publish --access public
Tag a releasenpm version patchpnpm version patch
Publish in monorepo(manual or Lerna)pnpm publish -r

LinkIconBonus

Tasknpmpnpm
Show outdated packagesnpm outdatedpnpm outdated
Audit for vulnerabilitiesnpm auditpnpm audit
Link local packagenpm linkpnpm link
List global packagesnpm list -g --depth 0pnpm list -g --depth 0
Add package in another workspace(cd into workspace manually)pnpm add lodash --filter=other-pkg

LinkIconpnpm exec

"Use package already installed in the project."

  • Runs a binary from your dependencies or globally installed (local node_modules/.bin)
  • It does not install anything new.
pnpm exec eslint src/

LinkIconpnpm dlx

"Temporarily download & execute a binary."

  • Temporarily installs a package, runs its CLI, then discards it.
  • Useful for one-off CLIs or generators you don’t want to install.
pnpm dlx create-next-app@latest my-app