pnpm — Fast, Disk-Efficient Node.js Package Manager

Practical guide to pnpm — a fast, disk-efficient package manager for Node.js with a content-addressable store and excellent monorepo support.

pnpm is a fast, exceptionally disk-efficient package manager for Node.js – a drop-in replacement for npm that reads the same package.json files. Instead of copying every dependency into each project, pnpm stores it once in a content-addressable store and links it into your projects with hard links, saving a huge amount of disk space and install time. Its strict node_modules layout makes sure you only access packages you actually declared, and in monorepos pnpm shows its biggest strength through first-class workspace support. This guide walks you through the commands you reach for daily – from installing and managing workspaces to keeping the store lean.

Install & Init

pnpm init — Create a new package.json.

pnpm init

pnpm install — Install all dependencies from package.json.

pnpm install

pnpm i — Shorthand for install.

pnpm i

pnpm install --frozen-lockfile — Install without updating lockfile (CI-safe).

pnpm install --frozen-lockfile

pnpm install --prod — Install only production dependencies.

pnpm install --prod

Add & Remove

pnpm add <package> — Add a package as dependency.

pnpm add express

pnpm add -D <package> — Add as dev dependency.

pnpm add -D typescript

pnpm add -g <package> — Install a package globally.

pnpm add -g serve

pnpm add <package>@<version> — Add a specific version.

pnpm add react@18.2.0

pnpm remove <package> — Remove a package.

pnpm remove lodash

pnpm rm <package> — Shorthand for remove.

pnpm rm lodash

Update & Info

pnpm update — Update all packages within their ranges.

pnpm update

pnpm update --latest — Update all packages to latest versions (ignoring ranges).

pnpm update --latest

pnpm outdated — Show outdated packages.

pnpm outdated

pnpm list — List installed packages.

pnpm list --depth=0

pnpm why <package> — Show why a package is installed.

pnpm why webpack

Scripts & Run

pnpm run <script> — Run a script from package.json.

pnpm run build

pnpm <script> — Shorthand for common scripts (start, test, etc.).

pnpm test

pnpm dlx <package> — Execute a package without installing (like npx).

pnpm dlx create-next-app my-app

pnpm exec <command> — Execute a command from node_modules/.bin.

pnpm exec tsc --version

Workspaces & Filtering

pnpm -r <command> — Run a command in all workspace packages recursively.

pnpm -r build

pnpm --filter <name> <command> — Run a command in a specific workspace package.

pnpm --filter @myapp/api build

pnpm --filter '<pattern>' <command> — Run in packages matching a glob pattern.

pnpm --filter './packages/*' test

pnpm --filter '...<name>' <command> — Run in a package and all its dependencies.

pnpm --filter '...@myapp/web' build

pnpm -r --parallel <command> — Run in all packages in parallel.

pnpm -r --parallel lint

Store & Config

pnpm store status — Check for modified packages in the store.

pnpm store status

pnpm store prune — Remove unreferenced packages from the store.

pnpm store prune

pnpm store path — Show the location of the content-addressable store.

pnpm store path

pnpm config list — Show all configuration settings.

pnpm config list

pnpm config set <key> <value> — Set a configuration value.

pnpm config set store-dir /custom/store

Conclusion

pnpm is the right choice when disk space, install speed and a clean dependency layout matter to you – especially in monorepos with many packages. In CI pipelines, always rely on pnpm install --frozen-lockfile: it installs exactly the committed pnpm-lock.yaml and refuses to silently update it, which guarantees reproducible builds. Keep an eye on your dependencies' install scripts too – they are a classic supply-chain vector – and pin versions rather than letting them float. Use pnpm store prune to keep the shared store lean without losing packages still in use.

Further Reading

  • npm – the default Node.js package manager
  • yarn – alternative JavaScript package manager with workspaces
  • nvm – manage multiple Node.js versions side by side