What magic is this? Faster npm with PnPm

Node.js is the most popular javascript runtime environments and it is extremely popular amongst developers. It uses npm as its package manager. Another alternative to npm is yarn which is touted to be more performant (i.e. faster than npm), however not fast enough.

Issues With Npm/Yarn

The main issue that many developers have with npm is that it is slow when used on projects with really big dependecies, also it does not manage the creation of the node_modules efficiently, duplicating dependencies across multiple projects.

Introducing PnPm

Here comes PnPm, a highly performant (fast) new package manager for node.js with the efficient disk space management. Pnpm is a drop in replacement for npm, it incorporates all the features of npm and it does it more efficiently.

Features of PnPm

  • Up to 2 times faster than npm
  • Shareable node_modules content, i.e – Files inside node_modules are stored in a single content-addressable storage, this is then cloned or hard-linked to projects where the libraries are used. This can greatly reduce disk space usage by removing the need for duplications.
  • PnPm Workspaces – This allows developers to isolate concerns by using multiple packages in a repository.
  • Peers installation
  • Patching dependencies and so much more…

Enough Talk, How do you install it?

To install PnPm is very easy, explore the following options

  1. Install using npm

To install PnPm using npm, there are two available packages for the pnpm CLI, namely, pnpm and @pnpm/exe.

  • pnpm is a ordinary version of pnpm, which needs Node.js to run.
  • @pnpm/exe is the version packaged with Node.js into an executable, so it can be executed on a system with no Node.js installed.
$ npm install -g pnpm

or 

$ npm install -g @pnpm/exe

 2. On macOs, using Homebrew

If you are on macOs, you can use the brew package manager to install pnpm as follows.

$ brew install pnpm

You can see other installation methods over here

How to use PnPm

That is the interesting thing, it is a drop-in replacement for npm, so all npm commands apply to pnpm also, just replace npm with pnpm, e.g

  • To install all dependencies, run pnpm install
  • To install a package, run pnpm install @faker-js/faker
  • etc.