pnpm Commands

pnpm commands cheatsheet.

Install, add, run and manage workspaces — the pnpm commands you use every day. Tap to copy.

Project setup
pnpm initCreate a package.json in the current folder
pnpm installInstall all dependencies from package.json
pnpm iShorthand for pnpm install
Dependencies
pnpm add <pkg>Add a package as a dependency
pnpm add -D <pkg>Add a package as a dev dependency
pnpm add -g <pkg>Install a package globally
pnpm add <pkg>@<version>Add a specific version of a package
pnpm remove <pkg>Remove a package
pnpm updateUpdate packages within allowed ranges
Running
pnpm <script>Run a package.json script by name
pnpm run <script>Run a custom script from package.json
pnpm startRun the start script
pnpm testRun the test script
pnpm dlx <pkg>Run a package binary without installing it
pnpm exec <cmd>Run a binary installed in node_modules
Info & maintenance
pnpm why <pkg>Show why a package is installed
pnpm outdatedShow packages with newer versions available
pnpm listList installed packages
pnpm auditCheck dependencies for known vulnerabilities
pnpm store pruneRemove unreferenced packages from the store
Workspaces / monorepo
pnpm -r <cmd>Run a command in every workspace package
pnpm --filter <name> <cmd>Run a command in one workspace package
pnpm -w add <pkg>Add a dependency to the workspace root

What pnpm actually does

pnpm is a fast, disk-efficient package manager for Node.js projects, a drop-in alternative to npm and Yarn that reads the same package.json. Its headline trick is storage: instead of copying every dependency into each project, pnpm keeps one global content-addressable store and hard-links packages from it into your node_modules. The same version of a package is only ever written to disk once, no matter how many projects use it, so installs are quick and take far less space. As with any project, a single pnpm install reads package.json and sets up everything the code needs.

Adding the right way

pnpm uses add rather than install for individual packages. pnpm add <pkg> adds a normal dependency your app needs to run. pnpm add -D <pkg> marks it as a dev dependency — tools like test runners and bundlers that you need while building but not in production. pnpm add -g <pkg> installs globally so a command-line tool is available everywhere, and pnpm add <pkg>@<version> pins an exact version. Getting these distinctions right keeps your project lean and your deployments clean.

Scripts, dlx and exec

The scripts section of package.json is where projects define their commands. pnpm lets you run a script just by its name — pnpm <script> — or spell it out with pnpm run <script>, with start and test getting their own shortcuts. For one-off tools, pnpm dlx <pkg> downloads and runs a package's binary without adding it to your project (pnpm's answer to npx), while pnpm exec runs a binary that is already installed in node_modules.

Monorepos and maintenance

pnpm has first-class workspace support, which is why many monorepos reach for it. pnpm -r <cmd> runs a command across every package, and pnpm --filter <name> <cmd> targets just one. For upkeep, pnpm outdated shows what has newer versions, pnpm update moves them forward within safe ranges, pnpm why <pkg> explains why something is installed, and pnpm store prune clears unreferenced packages from the global store. These pair naturally with the npm commands you may already know and the Git commands for version control.

FAQ

How does pnpm save disk space?
pnpm keeps a single content-addressable store on your machine and hard-links packages from it into each project's node_modules, so the same dependency version is stored on disk only once no matter how many projects use it.
How do I run a command in one workspace package?
Use pnpm --filter <name> <command> to target a single package in a monorepo, for example pnpm --filter web build. Use pnpm -r <command> to run it across every workspace package.
What's the difference between pnpm dlx and pnpm exec?
pnpm dlx downloads and runs a package's binary without adding it to your project, like npx; pnpm exec runs a binary that is already installed in your project's node_modules.

More cheatsheets