Tool: pnpm - Fast And Lean Package Manager for Node.js

10/16/20191 Min Read — In Node.js, JavaScript

A few days ago, I switched to fnm as my version manager for Node.js.

Before, I installed the default nodejs package that came with Arch Linux. But sometimes I would update my operating system, and thus getting a new Node.js version, and my system would break.

With fnm, I have fine-grained control over which version of Node.js I'm running.

Now, let's talk about package managers. Node.js ships with npm as the default package manager.

Yarn is a popular alternative to npm. Facebook developed yarn as a streamlined and safer solution to npm.

Nowadays, in 2019, npm has caught up, and both are viable choices.

But there's a new kid on the block!

In blog posts about yarn and npm, the new pnpm comes up again and again.

Why?

  • it's much faster
  • it uses symlinks to save one version of the module instead of storing new modules in every project
  • support for workspaces (for monorepos)
  • it has strict, non-flat node_modules folder

The API is similar to npm. For most cases, you can just switch from npm to pnpm and everything works fine.

Caveat: global modules:
I minimize what I install globally. But some packages (i.e., reason-cli) require a global installation.

From my experience of the last few days, it's easier to install global packages with npm or yarn. I got weird errors (for example with reason-cli and neovim-node-host) with pnpm global installations.

Gatsby is another library that doesn't work.

My advice is to install a few selected packages globally with npm/yarn. Install the rest locally with pnpm. Use Gatsby with npm/yarn.