DEV Community

Alex Spinov
Alex Spinov

Posted on

pnpm Has a Free API — Here's How to Manage Packages 2x Faster Than npm

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Workspace (Monorepo)

# pnpm-workspace.yaml
packages:
  - "apps/*"
  - "packages/*"
Enter fullscreen mode Exit fullscreen mode
# 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

.npmrc Configuration

# .npmrc
shared-workspace-lockfile=true
link-workspace-packages=true
auto-install-peers=true
strict-peer-dependencies=false
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)