Skip to content

Instantly share code, notes, and snippets.

@bradtraversy
Created January 25, 2018 14:08
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 36 You must be signed in to fork a gist
  • Save bradtraversy/9bdab9c9a0bf94e2c6952d3f89e9e350 to your computer and use it in GitHub Desktop.
Save bradtraversy/9bdab9c9a0bf94e2c6952d3f89e9e350 to your computer and use it in GitHub Desktop.
# GET VERSION
yarn -v (or --version)
# GET HELP
yarn help
# CREATE PACKAGE.JSON
yarn init
yarn init -y // Use defaults
# SET DEFAULTS
yarn config set init-license ISC
# GET DEFAULTS
yarn config get init-license
# REMOVE DEFAULTS
yarn delete init-license
# INSTALLING LOCAL PACKAGES
yarn add lodash
yarn add moment
# INSTALL FROM PACKAGE.JSON
(add "gulp":"*")
yarn install
# REMOVING MODULES
yarn remove lodash
# INSTALL CERTAIN VERSIONS
yarn add lodash@4.17.3
# FIND OUTDATED VERSIONS
yarn outdated lodash
yarn outdated
# UPGRADE
yarn upgrade lodash
yarn upgrade
# INSTALL GLOBAL MODULE (global must be put right after yarn)
yarn global add nodemon
# FIND ROOT FOLDER
yarn global bin
# REMOVE GLOBAL PACKAGES
yarn global remove nodemon
# LISTING PACKAGES
yarn list
yarn list --depth=0
yarn list --depth=1
yarn list --pattern gulp
# INSTALLING AS DEV DEPENDENCY
yarn add gulp -D or --dev
# REMOVE DEV DEPENDENCY
yarn remove gulp
#VERIFY THAT VERSIONS MATCH LOCK FILE
yarn check
# CREATE YARN.LOCK FILE
yarn import
# ADD SCRIPT
"scripts": {
"dev": "nodemon index.js"
},
# RUN SCRIPT
yarn run dev
# GET LICENSES
yarn license
# CREATE GZIP ARCHIVE OF DEPENDENCIES
yarn pack
yarn pack mydep
# LIST GLOBAL CACHE PACKAGES
yarn cache list
yarn cache list --pattern lodash
@devSahinur
Copy link

Thanks for sharing this comprehensive list of Yarn commands! It's a handy reference for anyone working with Yarn for JavaScript package management. These commands cover everything from basic package installation and management to more advanced tasks like setting defaults, managing global packages, and checking for outdated dependencies.

One additional tip I'd like to share is to consider using Yarn workspaces when working on projects with multiple packages/modules. Yarn workspaces can simplify package management for monorepos by allowing you to manage dependencies and scripts across multiple packages in a single repository.

Overall, this gist is a valuable resource for both beginners and experienced developers using Yarn. Great job putting it together!

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