They All Install Packages
The differences are in speed, features, and disk usage.
npm (Default)
Comes with Node.js. Good enough for most projects.
npm install
npm install lodash
npm install -D jest # dev dependency
npm update
npm run build
Lock file: package-lock.json
yarn (Facebook)
Faster, better workspaces support.
yarn
yarn add lodash
yarn add -D jest
yarn upgrade
yarn build
Lock file: yarn.lock
pnpm (Performance)
Saves disk space with symlinks. Fastest installs.
pnpm install
pnpm add lodash
pnpm add -D jest
pnpm update
pnpm build
Lock file: pnpm-lock.yaml
Speed Comparison
Typical install times (varies by project):
| Package Manager | Cold Install | Warm Cache | |----------------|--------------|------------| | npm | ~45s | ~20s | | yarn | ~30s | ~10s | | pnpm | ~25s | ~5s |
Monorepo Workspaces
All three support workspaces:
// package.json
{
"workspaces": ["packages/*"]
}
yarn and pnpm have better workspace ergonomics.
My Take
- New project: Use npm (simplest, no extra install)
- Monorepo: Use yarn or pnpm
- Disk space matters: Use pnpm
- Team preference: Whatever they know
Don't mix package managers in one project. Pick one.
