Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonlabelle/c082700c1c249d986faecbd5abf7d65b to your computer and use it in GitHub Desktop.
Save jonlabelle/c082700c1c249d986faecbd5abf7d65b to your computer and use it in GitHub Desktop.
npm vs yarn command translation cheat sheet
title subtitle author date source
npm vs Yarn Command Translation Cheat Sheet
CLI commands comparison
yarn
February 15, 2020

npm vs Yarn Command Translation Cheat Sheet

npm Yarn
npm init yarn init
npm install yarn install
(N/A) yarn install --flat
(N/A) yarn install --har
(N/A) yarn install --no-lockfile
(N/A) yarn install --pure-lockfile
npm install [package] (N/A)
npm install --save [package] yarn add [package]
npm install --save-dev [package] yarn add [package] --dev
(N/A) yarn add [package] --peer
npm install --save-optional [package] yarn add [package] --optional
npm install --save-exact [package] yarn add [package] --exact
(N/A) yarn add [package] --tilde
npm install --global [package] yarn global add [package]
npm update --global yarn global upgrade
npm rebuild yarn add --force
npm uninstall [package] (N/A)
npm uninstall --save [package] yarn remove [package]
npm uninstall --save-dev [package] yarn remove [package]
npm uninstall --save-optional [package] yarn remove [package]
npm cache clean yarn cache clean
rm -rf node_modules && npm install yarn upgrade
npm version major yarn version --major
npm version minor yarn version --minor
npm version patch yarn version --patch
@barhoring
Copy link

yarn init <=> npm init

@skube
Copy link

skube commented Mar 13, 2020

init commands yield slightly different results:

yarn init -y

{
  "name": "example-yarn-init-y",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT"
}

npm init -y

{
  "name": "example--npm-init-y",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

@ptletski
Copy link

As pointed out by barhoring commented on Feb 13, please correct the npm init and yarn init entries by swapping them. Many thanks.

@jonlabelle
Copy link
Author

Fixed.

@ekkis
Copy link

ekkis commented Nov 4, 2022

apparently one can also do yarn start, which is not documented above

@aspiers
Copy link

aspiers commented Jan 31, 2023

This is out of date now, yarn global is removed in 2.x.

@jcollum-nutrien
Copy link

Would be helpful to add the yarn version at the top, just to clarify. Yarn 2 has breaking changes vs 1.

@Des-Nerger
Copy link

yarn just-build is equivalent to npm run just-build.

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