Hi Developers! 👋
Let's talk about something almost every JavaScript developer uses but doesn't always think deeply about.
npm vs pnpm — Which one do you use, and why?
Imagine you're building an e-commerce application like Amazon or Flipkart. 🛒
Your application needs:
- React or Next.js for the frontend.
- Axios for API communication.
- Redux for state management.
- Tailwind CSS for styling.
- Authentication libraries for user login.
- Payment integrations.
- Many other packages.
How do you bring all these packages into your project?
You simply run:
npm install Everything gets installed, and you're ready to start coding.
But one day, you join a development team and notice that everyone is using:
pnpm install Wait a minute! Why pnpm? Isn't npm already doing the same job?
That's where the interesting discussion begins!
🛒 First, what exactly is a package manager?
Think of a package manager as your shopping assistant.
Imagine you're opening an online shopping store. You need products, packaging materials, delivery services, and payment systems.
Instead of arranging everything manually, you have a system that manages all these requirements.
That's what a package manager does for your code.
Need Axios in your React application?
With npm:
npm install axios With pnpm:
pnpm add axios Both install the package and make it available in your project.
So, if both do the same job, what's actually different?
Let's explore!
💾 1. Disk Space: Are we storing the same thing multiple times?
Imagine you're building an Amazon-like platform.
As the application grows, your company develops multiple frontend applications:
- Customer Shopping Website
- Seller Dashboard
- Admin Dashboard
- Delivery Partner Application
All four applications use React.
With npm
Each project generally has its own installed copy of React inside its node_modules directory.
ecommerce-platform/ │ ├── customer-app/ │ └── node_modules/react/ │ ├── seller-dashboard/ │ └── node_modules/react/ │ ├── admin-dashboard/ │ └── node_modules/react/ │ └── delivery-app/ └── node_modules/react/ The same package content may be stored multiple times.
With pnpm
pnpm uses something called a content-addressable store.
In simple words, it keeps reusable package content in a shared location on your computer. Different projects can link to that content instead of storing independent copies.
ecommerce-platform/ │ ├── customer-app/ │ └── node_modules/ │ ├── seller-dashboard/ │ └── node_modules/ │ ├── admin-dashboard/ │ └── node_modules/ │ └── delivery-app/ └── node_modules/ ↓ Reuse package content Shared pnpm Store └── React package content Instead of unnecessarily duplicating package content, pnpm can reuse it wherever possible.
Pretty smart, right? 😄
Question: If you're managing multiple applications, wouldn't you prefer a tool that makes better use of your disk space?
⚡ 2. Installation Speed: Who gets the job done faster?
Let's say your Amazon-like application has hundreds of dependencies.
You run an installation command, and now you have to wait.
Here's where pnpm can have an advantage.
If a package is already available in its local store, pnpm can reuse it instead of downloading it again.
This becomes particularly useful when:
- You work on multiple projects.
- You frequently install dependencies.
- You switch between branches.
- Your applications have large dependency trees.
But let's be fair: pnpm isn't always faster. Network speed, caching, hardware, and project size all matter.
The interesting thing is that pnpm focuses not only on installing packages but also on reusing what you already have.
🔐 3. The hidden dependency problem
This is one of my favourite differences!
Imagine you're developing the checkout page of your e-commerce application.
You write:
import axios from "axios"; But you never installed Axios directly.
How is it working?
Sometimes another package has installed Axios as its own dependency, and your application accidentally accesses it.
This is known as an undeclared or phantom dependency.
npm's traditional dependency layout can sometimes allow this situation.
pnpm takes a stricter approach.
If Axios isn't declared in your project, pnpm generally won't let your application access it just because another package happens to use it.
The solution?
pnpm add axios Now Axios is officially declared in your project.
Why does this matter?
Imagine your checkout page suddenly stops working after another developer updates an unrelated package.
You might spend hours debugging something that happened because your application depended on a package it never officially declared.
Stricter dependency management helps prevent these hidden problems.
🏗️ 4. What about large applications like Amazon or Flipkart?
Let's imagine an e-commerce company has grown significantly.
It now has multiple applications:
ecommerce-platform/ │ ├── apps/ │ ├── customer-web/ │ ├── seller-dashboard/ │ ├── admin-panel/ │ └── delivery-app/ │ ├── packages/ │ ├── shared-ui/ │ ├── authentication/ │ ├── payment-utils/ │ └── common-api/ │ ├── package.json └── pnpm-workspace.yaml Now think about the situation.
The customer website and seller dashboard both need:
- Buttons
- Input fields
- Authentication components
- API utilities
- Common validation logic
Would you build everything separately for every application?
Of course not!
You can create shared packages and reuse them across applications.
This type of setup is called a monorepo.
Both npm and pnpm support workspaces.
However, pnpm is particularly popular in monorepo environments because of its workspace tooling, package management, and storage efficiency.
That's one reason many frontend teams choose pnpm for larger projects.
⚖️ 5. So, is npm bad?
Absolutely NOT!
npm is:
- Easy to get started with.
- Included with Node.js.
- Supported by a huge JavaScript ecosystem.
- Reliable for small, medium, and large applications.
But it can use more disk space across multiple projects, and its traditional dependency layout is more permissive.
pnpm is:
- Efficient with disk space.
- Good at reusing packages.
- Often faster in repeated installations.
- Stricter with dependency management.
- Excellent for monorepos.
However, pnpm also has a few things to consider:
- It needs separate installation.
- Strict dependency handling can expose problems in older or poorly configured packages.
- Some tools may expect a traditional flat
node_modulesstructure.
So, there's no reason to say npm is bad just because pnpm has some advantages.
🤔 6. Then, which one should we choose?
Here's how I would approach it.
Choose npm when:
- You're learning JavaScript or React.
- You're building a small personal project.
- Your existing project already uses npm.
- Your team uses npm.
Choose pnpm when:
- You're working with large frontend applications.
- You're managing multiple projects.
- Disk space and installation efficiency matter.
- You're working with monorepos.
- Your team has standardized on pnpm.
And one important rule:
If you join an existing project, don't randomly change its package manager. Follow the one your team has already chosen.
For example, if the project has:
pnpm-lock.yaml And its package.json specifies:
{ "packageManager": "pnpm@12.23.0" } Use the specified pnpm version and follow the team's workflow.
Consistency matters more than personal preference in a shared repository.
👨💻 7. A few commands worth knowing
| Operation | npm | pnpm |
|---|---|---|
| Install dependencies | npm install | pnpm install |
| Add package | npm install axios | pnpm add axios |
| Remove package | npm uninstall axios | pnpm remove axios |
| Add dev dependency | npm install -D eslint | pnpm add -D eslint |
| Start development | npm run dev | pnpm dev |
| Build project | npm run build | pnpm build |
| Update packages | npm update | pnpm update |
💬 Now, let's make this a real discussion!
I don't think there's one perfect answer for every project. It depends on what we're building and how we're working.
But I'm curious to know your experience:
- Which package manager do you currently use — npm, pnpm, or Yarn?
- Have you ever faced issues with
node_modules, dependency conflicts, or unexpectedly large disk usage? - If you were building an Amazon- or Flipkart-scale frontend application, which package manager would you choose?
- Do you think pnpm is worth switching to, or is npm already good enough?
Whether you're a student just starting with React or an experienced developer working on large applications, I'd love to hear your thoughts!
Let's learn from each other. 🚀
"Don't just choose a tool because everyone else is using it. Understand the problem, explore the alternatives, and choose the tool that makes your development better." 💡