What is PNPM?
When you land on the pnpm site, it will tell you it's a "Fast, disk space efficient package manager".
Like npm and Yarn, PNPM is used to install Node.js modules from the npm registry, but it introduces a different approach to package management.
How is it different?
The difference between PNPM and other package managers lies in how they store dependencies.
While npm and Yarn will duplicate dependencies for each project (if versions allow), PNPM uses a global store of dependencies on your machine and then creates hard links or symlinks from this store to your project's
Why is this useful? Because it gives us:
- Disk Space Savings: Since dependencies are stored once and shared across projects, you save a significant amount of disk space.
- Fast Installs: Linking files is much faster than copying them, so PNPM can be much quicker for subsequent installations.
- Consistency: The global store ensures that a package of a particular version always has the same content.
Okay, but now I want to install it
If you're still reading, I assume you want to try PNPM.
The easiest way to get it installed is with npm (if you already have it installed):
npm install -g pnpm
If not here's a link to the different ways you can install it without npm.
How to use PNPM
The PNPM CLI is similar to npm or Yarn.
To install a projects dependencies, navigate to your project's root directory and run:
Or to install a new package:
pnpm install some-package-name
You can also use the
-D flags when using
pnpm install to install
Or to run commands:
pnpm run some-command
Switching from npm or Yarn
If you're moving a project from npm or Yarn to PNPM, start by deleting your existing
node_modules directory and
pnpm install to recreate the
node_modules directory using PNPM's linking strategy.
Want more? PNPM's documentation offers a comprehensive guide and is an excellent resource for learning about more advanced features, troubleshooting, and getting the most out of PNPM.