learn.colinkim.dev

pnpm: what it is and why people use it

Learn what pnpm is, why it exists even though npm already exists, and what makes it attractive to many teams.

Once npm makes sense, pnpm is easier to place correctly.

It does the same kind of work:

  • install packages
  • record dependencies
  • run project scripts
  • maintain a lockfile

The difference is not the category of tool. The difference is the design of the workflow.

What pnpm is

pnpm is another package manager for the Node.js ecosystem.

A pnpm project still uses familiar pieces:

  • package.json
  • dependencies
  • devDependencies
  • scripts
  • a lockfile

So moving from npm to pnpm is not learning a new ecosystem. It is learning a different package manager inside the same ecosystem.

Why teams choose pnpm

The official pnpm site emphasizes three themes:

  • speed
  • saving disk space
  • strong workspace support

In practice, teams often choose pnpm because they want:

  • fast repeated installs
  • more efficient dependency storage
  • a strong fit for workspaces and monorepos
  • a workflow that is slightly stricter and more explicit

Those benefits matter most as repositories grow, but the basic command set stays small even in simpler projects.

What makes pnpm efficient

pnpm uses a content-addressable storage system that makes it more space-efficient than npm in multi-project setups.

The content-addressable store

When pnpm installs a package, it stores the files in a central location on your disk called the content-addressable store. This store is usually located in your home directory at ~/.pnpm-store.

The key insight is that identical files across different packages and versions are stored only once. For example, if ten different projects all use the same version of lodash, the files are stored just once in the store, not ten times.

Instead of copying files into each project’s node_modules, pnpm creates hard links from the store to your project. A hard link is a way for multiple directory entries to point to the same file on disk.

This has two practical benefits:

  1. Disk space: Multiple projects using the same dependencies consume far less disk space
  2. Install speed: Creating a hard link is much faster than copying files

When you update a dependency, only the changed files are added to the store. The unchanged files are already there and get reused.

Why this matters for workspaces

pnpm’s storage model is especially valuable for workspaces and monorepos. In a typical monorepo, multiple packages often share many of the same dependencies.

Instead of each workspace package storing its own copy of react or typescript, pnpm can share the files across all of them through hard links. This can result in dramatic disk space savings and faster installs in large codebases.

What stays the same in a pnpm project

A pnpm-based project still has the same broad structure as an npm project.

You still work with:

  • a package.json file
  • a project manifest that records dependencies
  • scripts that run development and build tasks
  • a lockfile

The lockfile name changes:

pnpm-lock.yaml

That is one of the quickest signals that a repository uses pnpm.

You will also usually still see a node_modules directory in a pnpm project. The tool manages dependencies differently under the hood, but the visible shape of the project still feels familiar to someone who has already seen npm.

Installing pnpm

The pnpm installation docs recommend Corepack as a modern setup path. They also note that older Corepack versions can have outdated signatures, so updating Corepack first is useful.

One practical setup flow is:

  1. Update Corepack:

    npm install —global corepack@latest

  2. Enable pnpm:

    corepack enable pnpm

  3. Pin a pnpm version in the project:

    corepack use pnpm@latest-10

That last command adds a packageManager field to package.json, which helps the project declare which pnpm version it expects.

A good mental model for pnpm

pnpm is a package manager for the same kinds of projects as npm, but many teams adopt it for efficiency, consistency, and workspace-heavy repositories.

That is enough context to start using its daily commands.

Quick Check

One answer

What is the main storage idea behind pnpm?

Choose the best answer and use it to track your progress through the lesson.

Progress

Quick checks

No quick checks in this lesson.

Mark lesson manually or answer quick checks to track progress.