pnpm is a fast, disk-efficient package manager. It uses hard links and a content-addressable store to save disk space and install packages significantly faster than npm or yarn.
Installation
npm install -g pnpm
# or
curl -fsSL https://get.pnpm.io/install.sh | sh
Basic Commands
# Install all dependencies
pnpm install
# Add a package
pnpm add express
pnpm add -D vitest
pnpm add -g typescript
# Remove a package
pnpm remove lodash
# Update packages
pnpm update
pnpm update --interactive # Choose which to update
Workspace (Monorepo)
# pnpm-workspace.yaml
packages:
- "apps/*"
- "packages/*"
# Run in specific workspace
pnpm --filter @myorg/web dev
# Run in all workspaces
pnpm -r build
# Add dependency to specific package
pnpm --filter @myorg/web add react
# Add internal dependency
pnpm --filter @myorg/web add @myorg/ui --workspace
Filtering
# Run only in changed packages
pnpm --filter "...[origin/main]" build
# Run in package and its dependencies
pnpm --filter @myorg/web... build
# Run in dependents of a package
pnpm --filter ...@myorg/ui build
.npmrc Configuration
# .npmrc
shared-workspace-lockfile=true
link-workspace-packages=true
auto-install-peers=true
strict-peer-dependencies=false
Why pnpm?
- 3x faster than npm for fresh installs
- 50-70% less disk space via content-addressable store
- Strict by default — prevents phantom dependencies
- Built-in monorepo support with workspaces
- Compatible — works with existing npm projects
Useful Commands
pnpm why lodash # Why is this package installed?
pnpm list --depth=0 # List top-level dependencies
pnpm audit # Security audit
pnpm exec vitest # Run binary
pnpm dlx create-next-app # Download and execute
Need to extract or automate web content at scale? Check out my web scraping tools on Apify — no coding required. Or email me at spinov001@gmail.com for custom solutions.
Top comments (0)