What is pnpm?
Performant npm (command name: pnpm) is a fast, disk-efficient package manager for Node.js that serves as an alternative to npm. Unlike npm, which comes bundled with Node.js, pnpm is a separate tool you install yourself.
Key differences with npm:
- Stores packages in a global cache and links them to projects via hard links.
Each package version is downloaded once and reused across all projects - Uses a stricter node_modules structure with symlinks, preventing packages from accessing undeclared dependencies
Benefits:
- For development: Dramatically faster installations and significant disk space savings specially good for developers when working on multiple projects
- For production: Since modern applications are containerized, improvements are modest - slightly faster builds and marginally smaller container images due to deduplicated sub-dependencies. It introduces no overhead while providing small benefits, making it a solid choice for production environments
Install
# Using npm
npm install -g pnpm
# Using Homebrew
brew install pnpm
# Using curl (standalone)
curl -fsSL https://get.pnpm.io/install.sh | sh -
Configure
pnpm needs the $PNPM_HOME environment variable to be properly configured. It also needs to be added to your $PATH. The command below will set this up and modify ~/.zshrc so future terminal sessions work correctly.
pnpm setup
Now open a new terminal window and continue there OR apply the changes manually in the current session: source ~/.zshrc
Verify Installation
Check pnpm is installed
pnpm --version
# As of December 2025, should be something like: 10.x.y
Check where pnpm is installed
which pnpm
Verify pnpm store location
pnpm store path
# Should show something like: /Users/yourusername/Library/pnpm/store/v10
Basic Usage
New project
Create package.json. Similar tonpm init
pnpm init
Install/Add a package
pnpm add react # Adds to dependencies in package.json
pnpm add -D typescript # Adds to devDependencies in package.json
pnpm add -g nodemon # Global install, not added to any package.json
Existing projects
Install all dependencies from package.json. Equivalent to npm install
pnpm install
# or just
pnpm i
Run scripts
Execute a "dev" script defined in "scripts" section in package.json. Equivalent to npm run dev
pnpm run dev
# or omit 'run'
pnpm dev
Other common commands
pnpm remove <package> # Uninstall and remove from package.json
pnpm update # Update dependencies
pnpm list # List installed packages
pnpm outdated # Check for outdated packages
That is all. See you later 🐊!
0 comments :
Post a Comment