Skip to content

Instantly share code, notes, and snippets.

@mosioc
Last active December 26, 2025 15:44
Show Gist options
  • Select an option

  • Save mosioc/457caded4ff15436d0085cb5d2a1ffce to your computer and use it in GitHub Desktop.

Select an option

Save mosioc/457caded4ff15436d0085cb5d2a1ffce to your computer and use it in GitHub Desktop.
Node.js package managers cheat sheet

Node.js Package Managers Cheat Sheet

A quick reference for pnpm, Yarn, and npm commands, organized by task, including advanced commands and flags.

1. Project Setup

Action pnpm Yarn npm
Initialize a new project pnpm init yarn init npm init
Install all dependencies pnpm install yarn install or yarn npm install or npm i
Install with frozen lockfile pnpm install --frozen-lockfile yarn install --frozen-lockfile npm ci
Install only production dependencies pnpm install --prod yarn install --production npm install --production
Install exact version of a package pnpm add <package>@<version> yarn add <package>@<version> npm install <package>@<version>
Install package from Git repo pnpm add <git-url> yarn add <git-url> npm install <git-url>

2. Managing Dependencies

Action pnpm Yarn npm
Add a dependency pnpm add <package> yarn add <package> npm install <package>
Add a development dependency pnpm add -D <package> yarn add <package> -D npm install <package> -D
Add a peer dependency pnpm add -P <package> yarn add <package> -P npm install <package> --save-peer
Remove a dependency pnpm remove <package> yarn remove <package> npm uninstall <package>
Update dependencies pnpm update yarn upgrade npm update
Update a specific package pnpm update <package> yarn upgrade <package> npm update <package>
Check outdated dependencies pnpm outdated yarn outdated npm outdated
List installed packages pnpm list yarn list npm list
View package info pnpm info <package> yarn info <package> npm view <package>
Install exact versions (lock) pnpm add <package> --save-exact yarn add <package> --exact npm install <package> --save-exact

3. Running Scripts

Action pnpm Yarn npm
Run a custom script pnpm run <script> yarn run <script> npm run <script>
Start project pnpm start yarn start npm start
Run tests pnpm test yarn test npm test
Run a script in parallel (workspace) pnpm -r run <script> yarn workspaces run <script> npm run <script> (with lerna or npm-workspaces)

4. Global Packages

Action pnpm Yarn npm
Install a global package pnpm add -g <package> yarn global add <package> npm install -g <package>
Remove a global package pnpm remove -g <package> yarn global remove <package> npm uninstall -g <package>
List global packages pnpm list -g yarn global list npm list -g

5. Caching

Action pnpm Yarn npm
Clean cache pnpm cache clean yarn cache clean npm cache clean --force
Verify cache integrity pnpm store status yarn cache list npm cache verify

6. Auditing & Security

Action pnpm Yarn npm
Audit dependencies pnpm audit yarn audit npm audit
Fix audit issues automatically pnpm audit fix yarn audit --fix npm audit fix

7. Version Management

Action pnpm Yarn npm
Bump package version pnpm version <new-version> yarn version --new-version <new-version> npm version <new-version>
Bump major/minor/patch pnpm version major/minor/patch yarn version --major/--minor/--patch npm version major/minor/patch
Tag a release pnpm version <version> --tag <tag> yarn version --new-version <version> --tag <tag> npm version <version> --tag <tag>

8. Workspaces & Monorepo

Action pnpm Yarn npm
Add workspace pnpm add <package> -w yarn workspace <workspace-name> add <package> npm install <package> --workspace <workspace-name>
Run script in all workspaces pnpm -r run <script> yarn workspaces run <script> npm run <script> --workspaces
List all workspace packages pnpm list -r yarn workspaces info npm ls --workspaces

Tip: pnpm and Yarn workspaces provide efficient dependency sharing and are faster in monorepo setups compared to npm. Always check the lockfile (pnpm-lock.yaml, yarn.lock, package-lock.json) to ensure reproducible installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment