Biswa Rout
About Posts
Back to posts
Cover image for npm, Yarn, pnpm and Bun: Package Managers Explained Simply

npm, Yarn, pnpm and Bun: Package Managers Explained Simply

21 Nov 2025 • 11 min read

If you’ve ever stared at npm, Yarn, pnpm, and Bun and wondered which one to actually use, you’re not alone.

When you build JavaScript projects today, you’re not just writing code. You’re also choosing who manages your packages, builds your app, and keeps everything consistent. For years, npm ruled without competition. Then Yarn showed up. Then pnpm arrived with a smarter design. Now Bun is trying to rebuild the entire experience from scratch.

Let me break down what makes each one different so you can actually decide which fits your workflow.

Understanding the Four Players

npm: The default everyone knows

npm ships with Node.js and controls the largest package registry in the JavaScript world.

Installing a package:

npm install axios

Running a script:

npm run build

It works everywhere. Every library expects it to work.

The biggest advantage? Simplicity and universal compatibility. The biggest downside used to be speed and inconsistent installs. npm has gotten way better in recent years, but there are still faster options out there.

Yarn: The first serious challenger

Facebook created Yarn because npm had performance problems back then. Yarn brought reliability with lockfiles, added workspaces, and introduced an optional feature called Plug and Play.

Installing with Yarn:

yarn add axios

Yarn workspaces (package.json):

{
  "private": true,
  "workspaces": [
    "packages/api",
    "packages/web"
  ]
}

Workspaces made monorepos way easier to manage.

Yarn Plug and Play

Plug and Play removes node_modules and replaces it with a virtual resolution system. It can speed up installs and reduce clutter, but some tools still expect node_modules to exist.

If you want customizable tooling and powerful monorepo support, Yarn is solid.

pnpm: The clever and strict one

pnpm is exploding in popularity because it saves disk space and enforces strict dependency rules. It uses a content-addressed storage system that keeps one copy of each package on your machine. All your projects just link to that single store.

Installing packages:

pnpm add axios

Why pnpm saves space

If you have 20 projects using React, npm and Yarn will store React 20 times.

pnpm stores React once and creates links to it.

Why pnpm prevents hidden bugs

Traditional node_modules flattening sometimes lets you import packages you never directly installed.

Mistake example:

import lodash from "lodash"

If you didn’t install lodash but another package depended on it, npm or Yarn might still allow this. pnpm won’t. It makes every dependency explicit.

pnpm workspace setup:

`packages:

  • “apps/*”
  • “packages/*”`

This is one of the reasons teams love pnpm for monorepos.

Bun: The new kid rebuilding everything

Bun isn’t just a package manager. It’s a runtime, bundler, test runner, and toolchain all in one binary. It’s written in a language called Zig, which focuses on speed and low-level control. If you want to learn what Zig is, check out the official site at ziglang.org.

Bun uses JavaScriptCore, the same engine in Safari. It starts faster than Node.js in many cases.

Bun install:

bun install

This alone is incredibly fast.

Bun runtime example:

bun run index.ts

Bun HTTP example:

export default { port: 3000, fetch(req) { return new Response("Hello from Bun") } }

Run it with:

bun server.js

Bun feels refreshing because it tries to simplify the entire developer experience.

The main drawback? Bun is still very young. Some Node APIs and native modules might not behave exactly the same. But it’s improving fast.

image-1.jpg

A Real-World Comparison

FeaturenpmYarnpnpmBun
SpeedSlow to moderateFastVery fastExtremely fast
Disk usageHighHighVery lowLow
Monorepo supportBasicGreatExcellentBasic
node_modulesYesOptionalSmart node_modulesYes but optimized
RuntimeNoNoNoYes
BundlerNoNoNoYes

Which One Should You Choose?

Here’s the simple version.

  • Choose npm if you want maximum compatibility.
  • Choose Yarn if you want strong workspaces and extra tooling.
  • Choose pnpm if you want speed, strict dependency isolation, and a monorepo that feels clean.
  • Choose Bun if you want a fast runtime and an all-in-one toolset that simplifies your entire development flow.

There’s no single winner. Your choice depends on how you like to build and what you value more: stability, features, structure, or raw speed.

The bottom line? Pick the tool that matches your workflow, not the one everyone’s talking about.

When you build JavaScript projects today, you do not just write code. You also choose who manages your packages, builds your app and keeps everything consistent. For years, npm ruled this space without competition. Then Yarn challenged it. Then pnpm arrived with a smarter design. Now Bun is trying to rebuild the entire experience from the ground up.

If you ever felt confused about which one to use, you are not alone. Let me break them down with explanations, examples and a bit of context so the whole picture becomes clear.

Understanding the four players

npm: The default that everyone knows

npm ships with Node.js and controls the largest package registry in the JavaScript ecosystem.

To install a package:

npm install axios

To run a script:

npm run build

It works everywhere and every library expects it to work.

The biggest advantage of npm is simplicity and universal compatibility. The biggest downside used to be speed and inconsistent installs. npm has improved a lot in recent years, but there are still faster alternatives.


Yarn: The first serious challenger

Yarn was created by Facebook because npm had performance issues at the time. Yarn improved reliability with lockfiles, added workspaces and introduced an optional feature called Plug and Play.

Example: Yarn install

yarn add axios

Example: Yarn workspaces (package.json)

{
  "private": true,
  "workspaces": [
    "packages/api",
    "packages/web"
  ]
}

Workspaces made monorepos easy to manage.

Yarn Plug and Play

Plug and Play removes node_modules and replaces it with a virtual resolution system. It can speed up installs and reduce clutter, but some tools still expect node_modules.

If you want customisable tooling and powerful monorepo support, Yarn is great.


pnpm: The clever and strict one

pnpm is gaining massive popularity because it saves disk space and enforces strict dependency rules. It uses a content-addressed storage system that keeps one copy of each package on your machine. All projects link to that single store.

This is how it installs packages:

pnpm add axios

Why pnpm saves space

If you have 20 projects using React, npm and Yarn will store React 20 times.

pnpm stores React once and creates links to it.

Why pnpm prevents hidden bugs

Traditional node_modules flattening sometimes lets you import packages you never installed directly.

Example of a mistake:

import lodash from "lodash"

If you did not install lodash but another package depended on it, npm or Yarn may still allow this. pnpm will not. It makes every dependency explicit.

Example: pnpm workspace setup

packages:
  - "apps/*"
  - "packages/*"

This is one of the reasons many teams love pnpm when working with monorepos.


Bun: The new kid that is rebuilding everything

Bun is not just a package manager. It is a runtime, bundler, test runner and a toolchain all packed into one binary. It is written in a language called Zig, which focuses on speed and low level control. If you want to learn what Zig is, here is the official site:

https://ziglang.org/

Bun uses JavaScriptCore, the same engine used in Safari. It starts faster than Node.js in many cases.

Bun install

bun install

This alone is incredibly fast.

Bun runtime example

bun run index.ts

Bun HTTP example

export default {
  port: 3000,
  fetch(req) {
    return new Response("Hello from Bun")
  }
}

And run it with:

bun server.js

Bun feels refreshing because it tries to simplify the entire developer experience.

The main drawback is that Bun is still very young. Some Node APIs and native modules may not behave exactly the same. But it is improving fast.

A real world comparison

FeaturenpmYarnpnpmBun
SpeedSlow to moderateFastVery fastExtremely fast
Disk usageHighHighVery lowLow
Monorepo supportBasicGreatExcellentBasic
node_modulesYesOptionalSmart node_modulesYes but optimised
RuntimeNoNoNoYes
BundlerNoNoNoYes

Which one should you choose?

Here is the simple version.

  • Choose npm if you want maximum compatibility.
  • Choose Yarn if you want strong workspaces and extra tooling.
  • Choose pnpm if you want speed, strict dependency isolation and a monorepo that feels clean.
  • Choose Bun if you want a fast runtime and an all in one toolset that simplifies the entire development flow.

There is no single winner. Your choice depends on how you like to build and what you value more: stability, features, structure or raw speed.

Recommended Reads

Cover image for Waiting for Pebble, the Watch That Respected Time

Waiting for Pebble, the Watch That Respected Time

I broke my Pebble smartwatch in 2017. I tried an Apple Watch but was never happy, nothing else came close. Now, with Pebble's relaunch, I'm ready to believe in smartwatches again.

5 Jan 2026 • 5 min read
Cover image for Building a Blog with Notion, Astro, and Cloudflare Pages

Building a Blog with Notion, Astro, and Cloudflare Pages

Build a lightning-fast blog with Notion CMS, Astro, and Cloudflare Pages. One-click deployment, automatic image optimisation, and $0/month hosting.

16 Nov 2025 • 14 min read

© 2026 Biswa Rout

Privacy Policy