Getting started with pnpm

— 5 minute read

Photo by Ricardo Gomez Angel on Unsplash

Table of contents

What is pnpm?

pnpm is a “fast, disk efficient package manager”, which can be used as a drop-in replacement for most common npm commands.

  • Fast. Up to 2x faster than the alternatives (see benchmark).
  • Efficient. Files inside node_modules are linked from a single content-addressable storage.

pnpm

This means less time wasted installing dependencies and less disk space wasted by package duplication, as packages are installed centrally and then made available to your project’s node_modules folder via a set of symlinks/hardlinks.

Install dependencies

pnpm install --shamefully-hoist

This command is the equivalent of the npm install command, for when you need to install a set of project dependencies and devDependencies that are defined in the project’s package.json file.

--shamefully-hoist ensures that project dependencies are ‘installed’ (symlinked) in the root of your project’s node_modules folder, which prevents issues with dependencies that expect a flat node_modules structure. You can skip this parameter if that is not required for your project’s dependencies.

Official documentation: pnpm install --shamefully-hoist

Windows Terminal: pnpm install

Add a dependency

pnpm add <package-name>

Adds <package-name> as a project dependency and installs it.

Add a devDependency

pnpm add -D <package-name>

Adds <package-name> as a devDependency and installs it.

For more details and other useful pnpm commands see pnpm.