pnpm & The Content-Addressable Store

Understand how pnpm saves gigabytes of disk space and eliminates phantom dependencies using a global content-addressable store, hard links, and symlinks.

Package Managers5 min readConcept 14 of 24

What is pnpm and the Content-Addressable Store?

pnpm (Performant npm) is a modern Node.js package manager designed for extreme speed and disk efficiency. Unlike npm or Yarn which copy full dependency trees into every project on your computer, pnpm maintains a single global Content-Addressable Store (CAS) located at ~/.local/share/pnpm/store/v3 or %LOCALAPPDATA%\pnpm\store\v3.

Every file from every package version is stored once in the global store indexed by its cryptographic hash. Projects then link to these stored files using operating system hard links inside a hidden virtual directory named node_modules/.pnpm.

Why use pnpm instead of traditional flat node_modules?

Traditional package managers duplicate tens of thousands of identical files across multiple projects, wasting gigabytes of disk space and slowing down installations with heavy disk I/O.

Furthermore, flat hoisting in npm and Yarn v1 creates dangerous phantom dependencies where code can import packages not listed in package.json. pnpm solves both problems simultaneously: hard links provide 100% disk deduplication while strict symlink structures guarantee that projects can only import declared dependencies.

How Hard Links and Symlinks Construct the Node Modules Layout

When running pnpm install, pnpm checks the global CAS store for each package file. If missing, it downloads and saves the file to the global store once. It then creates hard links (fs.link) from node_modules/.pnpm/<name>@<version>/node_modules/<name> pointing directly to the global store inodes.

To make packages accessible to Node.js resolution, pnpm creates symbolic links (fs.symlink) from your project's root node_modules/<name> pointing into .pnpm. For nested dependencies, symlinks inside .pnpm/<parent>@<version>/node_modules/ point to the child dependency folder. Node.js standard parent directory lookup works out of the box without runtime loaders or monkey patching.

Explore pnpm Store Layout and Hard Link Structures

Simulate package installations across multiple projects to visualize global CAS store deduplication and symlink isolation in real time.

// Global Content-Addressable Store Path
~/.local/share/pnpm/store/v3/files/ (CAS Inodes)
// Hard Link Resolution Across Projects
Installed Packages in Global Store: 4 packages (21.9 MB)
Legacy Copying Cost (npm v6): 29.6 MB across 3 projects
Real Net Savings: 7.7 MB (26% disk reduction)
1. Select Project Context to Configure
Toggle Dependencies for Project ALPHA:
Global Store Deduplication Analysis
Traditional npm (File Duplication)29.6 MB
Copies identical package files into every project folder. 3 projects using React store 3 separate physical copies.
pnpm Hard-Linked CAS Store21.9 MB
Stores unique files once in ~/.local/share/pnpm/store/v3 and hard-links them to all projects.
Total Hard Disk Space Saved across Projects:
7.7 MB

Interactive pnpm Content-Addressable Store Lab: Toggle packages across 3 projects to observe space deduplication and symlink isolation

Remember this

  • pnpm stores files once in a global Content-Addressable Store (CAS) and links them via hard links into node_modules/.pnpm.
  • Root node_modules contains only symlinks for declared dependencies, completely preventing phantom dependency bugs.
  • Editing files inside node_modules directly corrupts the global CAS store for all projects sharing those hard links.
  • Use pnpm store status to check integrity and pnpm patch to modify package code safely.

Done with this concept?

Mark it complete to track your progress. No login needed.