skip to content

pnpm VS npm and yarn: why p?

/ 2 min read

Learn why I prefer pnpm compared to the good ol' npm

NPM vs. PNPM: A Tale of Two Package Managers

It all started as a casual glance through my Discord server. One of the members had posted a query about my use of pnpm in my articles. It got me thinking - why not explore this topic on a broader canvas? Why limit the response to a single individual, when the entire community might be grappling with the same question? So, dear reader, this post is a result of that spark, a discussion on pnpm versus npm, hopefully clearing up some doubts and providing useful insights along the way.

Let’s start with pnpm. It’s a package manager for JavaScript, similar to npm or yarn, but with a unique selling point. It’s efficient, fast, and more importantly, respects disk space. Born back in 2017, it was developed by Zoltan Kochan as an alternative to existing package managers, targeting the issue of duplicating packages on the disk, a problem known as “disk space waste.”

On the other hand, npm is like the granddaddy of JavaScript package managers. Released in 2010, it quickly became the default package manager for Node.js and held the monopoly in the package management space for quite a while. However, npm has had its share of issues, particularly around performance and disk usage, which led to the creation of alternatives like pnpm.

So, how does pnpm stand out from npm? The key difference lies in how they handle packages. pnpm uses a unique approach, where it creates a global store of packages and then links the necessary ones to your project. This way, if multiple projects use the same package, it’s fetched and stored only once, thus saving disk space.

Now, let’s dive into some practical examples of using pnpm. Installing pnpm is as easy as running a single command:

npm install -g pnpm

For adding a package to your project, you can use:

pnpm add <package-name>

And if you want to remove a package, simply use:

pnpm remove <package-name>

In conclusion, npm and pnpm both have their merits. However, if you’re looking for a package manager that is efficient, fast, and respects your disk space, pnpm is definitely worth a try. So, the next time you’re about to type npm install, consider giving pnpm a spin. You might find yourself pleasantly surprised.