# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/package-managers/pnpm/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Install & Init

`pnpm init` — Create a new package.json.

```bash
pnpm init
```

`pnpm install` — Install all dependencies from package.json.

```bash
pnpm install
```

`pnpm i` — Shorthand for install.

```bash
pnpm i
```

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

```bash
pnpm install --frozen-lockfile
```

`pnpm install --prod` — Install only production dependencies.

```bash
pnpm install --prod
```

## Add & Remove

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

```bash
pnpm add express
```

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

```bash
pnpm add -D typescript
```

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

```bash
pnpm add -g serve
```

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

```bash
pnpm add react@18.2.0
```

`pnpm remove <package>` — Remove a package.

```bash
pnpm remove lodash
```

`pnpm rm <package>` — Shorthand for remove.

```bash
pnpm rm lodash
```

## Update & Info

`pnpm update` — Update all packages within their ranges.

```bash
pnpm update
```

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

```bash
pnpm update --latest
```

`pnpm outdated` — Show outdated packages.

```bash
pnpm outdated
```

`pnpm list` — List installed packages.

```bash
pnpm list --depth=0
```

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

```bash
pnpm why webpack
```

## Scripts & Run

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

```bash
pnpm run build
```

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

```bash
pnpm test
```

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

```bash
pnpm dlx create-next-app my-app
```

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

```bash
pnpm exec tsc --version
```

## Workspaces & Filtering

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

```bash
pnpm -r build
```

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

```bash
pnpm --filter @myapp/api build
```

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

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

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

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

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

```bash
pnpm -r --parallel lint
```

## Store & Config

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

```bash
pnpm store status
```

`pnpm store prune` — Remove unreferenced packages from the store.

```bash
pnpm store prune
```

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

```bash
pnpm store path
```

`pnpm config list` — Show all configuration settings.

```bash
pnpm config list
```

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

```bash
pnpm config set store-dir /custom/store
```

<!-- PROSE:outro -->
## 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](https://pnpm.io/) – official documentation, configuration and workspace guide
- [pnpm – GitHub project](https://github.com/pnpm/pnpm) – source code, releases and issue tracker
<!-- PROSE:outro:end -->

## Related Commands

- [npm](https://www.jpkc.com/db/en/cheatsheets/package-managers/npm/) – the default Node.js package manager
- [yarn](https://www.jpkc.com/db/en/cheatsheets/package-managers/yarn/) – alternative JavaScript package manager with workspaces
- [nvm](https://www.jpkc.com/db/en/cheatsheets/package-managers/nvm/) – manage multiple Node.js versions side by side

