npm and Yarn duplicate packages across projects. pnpm uses hard links to share packages, saving gigabytes of disk space. At ZIRA Software, pnpm reduced our node_modules footprint by 70%.
Installation
# npm
npm install -g pnpm
# Homebrew
brew install pnpm
# Windows
iwr https://get.pnpm.io/install.ps1 -useb | iex
How pnpm Works
Traditional (npm/Yarn):
project-a/node_modules/lodash/ (4MB)
project-b/node_modules/lodash/ (4MB)
project-c/node_modules/lodash/ (4MB)
Total: 12MB
pnpm:
~/.pnpm-store/lodash@4.17.21/ (4MB, stored once)
project-a/node_modules/.pnpm/lodash -> store (hard link)
project-b/node_modules/.pnpm/lodash -> store (hard link)
project-c/node_modules/.pnpm/lodash -> store (hard link)
Total: 4MB
Basic Usage
# Install all dependencies
pnpm install
# Add package
pnpm add react
# Add dev dependency
pnpm add -D typescript
# Remove package
pnpm remove lodash
# Update packages
pnpm update
# Run scripts
pnpm run build
pnpm test
Workspaces
# pnpm-workspace.yaml
packages:
- 'packages/*'
- 'apps/*'
# Install in specific workspace
pnpm --filter app add react
# Run in all workspaces
pnpm -r build
# Run in specific workspace
pnpm --filter app dev
Migration from npm
# Remove old files
rm -rf node_modules package-lock.json
# Install with pnpm
pnpm install
# Import existing lock file
pnpm import
Performance
# Benchmarks (1000 packages)
npm install: 45s
yarn install: 35s
pnpm install: 20s (first run)
pnpm install: 5s (cached)
Conclusion
pnpm provides fastest installs and most efficient disk usage. Essential for developers with multiple JavaScript projects.
Need build optimization? Contact ZIRA Software for frontend tooling consultation.