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 initpnpm install — Install all dependencies from package.json.
pnpm installpnpm i — Shorthand for install.
pnpm ipnpm install --frozen-lockfile — Install without updating lockfile (CI-safe).
pnpm install --frozen-lockfilepnpm install --prod — Install only production dependencies.
pnpm install --prodAdd & Remove
pnpm add <package> — Add a package as dependency.
pnpm add expresspnpm add -D <package> — Add as dev dependency.
pnpm add -D typescriptpnpm add -g <package> — Install a package globally.
pnpm add -g servepnpm add <package>@<version> — Add a specific version.
pnpm add react@18.2.0pnpm remove <package> — Remove a package.
pnpm remove lodashpnpm rm <package> — Shorthand for remove.
pnpm rm lodashUpdate & Info
pnpm update — Update all packages within their ranges.
pnpm updatepnpm update --latest — Update all packages to latest versions (ignoring ranges).
pnpm update --latestpnpm outdated — Show outdated packages.
pnpm outdatedpnpm list — List installed packages.
pnpm list --depth=0pnpm why <package> — Show why a package is installed.
pnpm why webpackScripts & Run
pnpm run <script> — Run a script from package.json.
pnpm run buildpnpm <script> — Shorthand for common scripts (start, test, etc.).
pnpm testpnpm dlx <package> — Execute a package without installing (like npx).
pnpm dlx create-next-app my-apppnpm exec <command> — Execute a command from node_modules/.bin.
pnpm exec tsc --versionWorkspaces & Filtering
pnpm -r <command> — Run a command in all workspace packages recursively.
pnpm -r buildpnpm --filter <name> <command> — Run a command in a specific workspace package.
pnpm --filter @myapp/api buildpnpm --filter '<pattern>' <command> — Run in packages matching a glob pattern.
pnpm --filter './packages/*' testpnpm --filter '...<name>' <command> — Run in a package and all its dependencies.
pnpm --filter '...@myapp/web' buildpnpm -r --parallel <command> — Run in all packages in parallel.
pnpm -r --parallel lintStore & Config
pnpm store status — Check for modified packages in the store.
pnpm store statuspnpm store prune — Remove unreferenced packages from the store.
pnpm store prunepnpm store path — Show the location of the content-addressable store.
pnpm store pathpnpm config list — Show all configuration settings.
pnpm config listpnpm 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
- pnpm.io – official documentation, configuration and workspace guide
- pnpm – GitHub project – source code, releases and issue tracker