Skip to content
X

pnpm - Fast Package Manager

pnpm (Performant npm) is a Node.js package manager. It serves the same purpose as npm and yarn, but it stores packages in a global store using hard links, which makes it strong in both installation speed and disk usage.

npm copies packages into each project’s node_modules folder. If 10 projects use react, you get 10 copies.

pnpm uses hard links, which are references to files, and stores each package only once in a global store. Even if multiple projects use the same package, the physical data on disk exists only once.

In diagram form:

[With npm]
project-a/node_modules/react/  ← copy of react (15MB)
project-b/node_modules/react/  ← copy of react (15MB)
project-c/node_modules/react/  ← copy of react (15MB)
Total: 45MB used

[With pnpm]
~/.pnpm-store/react/           ← actual react data (15MB) only
project-a/node_modules/react   ← link (almost 0 bytes)
project-b/node_modules/react   ← link (almost 0 bytes)
project-c/node_modules/react   ← link (almost 0 bytes)
Total: 15MB used
Featurenpmpnpm
InstallationBuilt into Node.jsRequires separate installation
Installation speedStandardFast, with strong cache efficiency
Disk usageCopies per projectLarge savings with a global store
Dependency resolutionLoose (can access undeclared packages)Strict (only declared packages are accessible)
Command compatibility-Nearly the same as npm

If Node.js and npm are already installed, you can install pnpm with:

npm install -g pnpm
pnpm --version          # Check version

Corepack is a package-manager management tool that comes with Node.js. It lets you manage pnpm versions per project.

corepack enable                          # Enable Corepack
corepack prepare pnpm@latest --activate  # Activate the latest pnpm
pnpm --version                           # Check version

If you use nvm, switching Node.js versions can make a globally installed pnpm unavailable. That is because nvm keeps global packages separate per Node.js version.

Fix 1: Use Corepack

Corepack is not affected by nvm version switching. You can keep using pnpm after changing Node.js versions.

Fix 2: Reinstall after switching versions

nvm use 22
npm install -g pnpm      # Reinstall after switching

The command structure is close to npm, so it feels familiar if you have used npm before.

Actionnpmpnpm
Install dependenciesnpm installpnpm install
Add a packagenpm install <pkg>pnpm add <pkg>
Add a dev dependencynpm install -D <pkg>pnpm add -D <pkg>
Run a scriptnpm run devpnpm run dev or pnpm dev
Remove a packagenpm uninstall <pkg>pnpm remove <pkg>
Global installnpm install -g <pkg>pnpm add -g <pkg>
Show listnpm listpnpm list
Check for updatesnpm outdatedpnpm outdated
  • When you are just starting with JavaScript - It comes with Node.js, so you can use it right away without extra setup
  • For simple personal projects - If you only use a few packages, npm is enough
  • When your team is used to npm - In existing projects or teams where everyone already uses npm, stability may be worth more than migration cost
  • When you manage multiple projects in parallel - The global store can reduce both disk usage and installation time after the first run
  • When you want faster CI/CD installs - Caching works well and shortens test and build time
  • When disk space is limited - If the same package is used in multiple projects, pnpm stores only one physical copy
  • When you use a monorepo - pnpm is strong at workspace management

Start projects with npm, then consider pnpm when you hit situations such as:

  • node_modules becoming too large and using too much disk space
  • npm install taking too long
  • Repeatedly installing the same libraries across many projects

Migration is easy. In an existing project with a package.json, running pnpm install is enough.

pnpm is stricter than npm about dependency management. Packages not explicitly listed in package.json cannot be accessed from your code. This helps prevent bugs, but some libraries may need configuration changes.

In that case, create a .npmrc file in the project root and add:

# .npmrc (only when needed)
shamefully-hoist=true

Because this loosens pnpm’s strict dependency handling, keep it to the minimum necessary.

  • pnpm is a faster package manager with better disk efficiency than npm
  • Install it with npm install -g pnpm
  • In nvm environments, Corepack helps avoid problems when switching versions
  • The command structure is very similar to npm, so migration cost is low
  • It is especially useful when managing multiple projects or when installation speed matters

Q: Do I need pnpm if I already have npm?

A: It is not required, but you may get better installation speed and lower disk usage. The benefits are especially noticeable when you work on multiple projects or have limited disk space.

Q: Will existing npm projects still work with pnpm?

A: Yes. In an existing project with a package.json, running pnpm install is enough. However, it will create pnpm-lock.yaml instead of package-lock.json.

Q: What is the difference between yarn and pnpm?

A: Yarn is also an alternative to npm, but pnpm’s strengths are disk efficiency through its global store and strict dependency management. They are close in features, so choose based on project policy and existing setup.

Q: Should pnpm-lock.yaml be committed to Git?

A: Yes. Like package-lock.json, pnpm-lock.yaml ensures that everyone on the team uses the same package versions. It should be included in Git.