AI Workshop: learn to build apps with AI →
npm: What is pnpm?

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


node_modules folders can be large. Saving disk space is useful, especially on machines with limited storage.

One approach is to store packages in a single central location and share them across projects. That is what pnpm does: https://pnpm.io.

It is basically a drop-in replacement for npm, which means that once you install it, you can invoke pnpm install to download a project’s dependencies, and all will work transparently for you.

If you have 10 projects that use React, at the same version, pnpm will install it once, and then reference that first install across all your other projects.

This also means that the project initialization part takes much less time than if it had to download resources using the standard npm procedure. It’s faster even if npm cached the package, because pnpm makes a hard link to the central local repository, while npm makes a copy of the package from the cache.

Install pnpm with npm:

npm install -g pnpm

Then, since pnpm is a drop-in replacement, you can use all the usual npm commands:

pnpm install react
pnpm update react
pnpm uninstall react

and so on.

pnpm is especially appreciated in those companies where there is a need to maintain a large number of projects with the same dependencies.

pnpm recursive runs a command across all projects in a folder—for example, pnpm recursive install to install dependencies for every project in the current directory.

pnpm includes pnpx, which works like npx and uses pnpm’s store:

pnpx create-react-app my-cool-new-app

Packages are stored in ~/.pnpm-store/ (on macOS/Linux; ~ is your home directory). Example structure after installing lodash:

  ~ tree .pnpm-store/
.pnpm-store/
└── 2
    ├── _locks
    ├── registry.npmjs.org
    │   └── lodash
    │       ├── 4.17.11
    │       │   ├── integrity.json
    │       │   ├── node_modules
    │       │   │   └── lodash
    │       │   │       ├── ...
    │       │   ├── package -> node_modules/lodash
    │       │   └── packed.tgz
    │       └── index.json
    └── store.json

pnpm has more features; this covers the basics. Use it when it solves a need (e.g. saving disk space or faster installs); otherwise npm is fine for everyday use.

Lessons in this unit:

0: Introduction
1: How to use or execute a package installed using npm
2: npm dependencies and devDependencies
3: How to fix the "Missing write access" error when using npm
4: npm can install packages in the parent folder
5: Install an older version of an npm package
6: Find the installed version of an npm package
7: How to test an npm package locally
8: npm global or local packages
9: What are peer dependencies in a Node module?
10: `npm run dev` is a long-running program
11: Semantic Versioning using npm
12: Uninstalling npm packages with `npm uninstall`
13: An introduction to the npm package manager
14: The npx Node Package Runner
15: The package.json guide
16: The package-lock.json file
17: ▶︎ What is pnpm?
18: Should you commit the node_modules folder to Git?
19: Update all the Node dependencies to their latest version
20: Where does npm install the packages?
21: Bumping Node.js dependencies
22: Run package.json scripts upon any file changes in a folder