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 node_modules directory.

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:

pnpm install

Or to install a new package:

pnpm install some-package-name

You can also use the --dev or -D flags when using pnpm install to install devDependencies.

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 package-lock.json or yarn.lock file.

Then, run 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.

Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.