What is pnpm?
Instead of copying packages into
node_modules like npm does, pnpm symlinks packages from a global store on your disk. This avoids duplicating files across projects, saving huge amounts of disk space.
pnpm was created in 2017 by Zoltan Kochan, motivated by the disk space and speed problems of
Key Features and Benefits
Here are some of the standout features and benefits of using pnpm over npm or Yarn:
- Fast installation: pnpm installs dependencies in parallel using hard links. This makes installation up to 3x faster.
- Lower disk usage: By symlinking from a global store instead of copying, pnpm saves over 90% in disk space.
- Built-in dependency optimization: pnpm dedupes and hoists common dependencies for faster installs.
- Strictness: pnpm uses checksums and a content-addressed file system to avoid dependency conflicts.
- Scales to large projects: pnpm remains performant and efficient even for projects with hundreds of dependencies.
- Backward compatibility: pnpm ensures compatibility with npm registries and the wider Node.js ecosystem.
How pnpm Works
pnpm manages dependencies in a fundamentally different way from npm and Yarn under the hood. Here’s a quick look at how it works:
- Packages are stored in a single, global
- Instead of copying packages into
node_modules, pnpm creates symlinks from the store.
- The store uses content-addressing – packages are saved by content hash, avoiding duplication.
- A shrinkwrap file locks down the dependency tree. Adding a new package creates a new lockfile.
- Transitive dependency hoisting is used to flatten module locations.
This optimized install strategy allows super fast installs and reduced disk usage. The store persists across projects to maximize efficiency.
Why Use pnpm?
Here are some of the top reasons to switch to pnpm:
- blazing fast installs – you get your dependencies 3x faster
- save over 90% in disk space for your projects
node_modulesduplications across projects
- strictness and reproducibility with content-addressing
- efficient dependency optimization under the hood
- excellent scaling even for massive projects
- easy migration from npm
To start using pnpm, first install it globally:
npm install -g pnpm
Then install dependencies in your project:
That’s it! pnpm will now manage your packages from its global store.
To learn more about migrating from npm or Yarn and using pnpm effectively, check out the excellent pnpm docs.
With its content-addressable store, symlinking strategy, and built-in optimization, pnpm unlocks game-changing benefits in install speed, disk usage, and strictness.