yarn, npm

Yarn vs npm

Comparing Yarn and npm Node package managers

Note on Yarn

We strongly suggest using Yarn as a package manager.

We prefer to use Yarn as a package manager for Node as it provides more stable installations for large repositories. See this article on why it is worth using yarn over npm.

Below is a comparison of key commands between npm and Yarn.

Yarn vs npm cheatsheet

Starting a new project

npm init
yarn init

Install all packages from package.json

npm install

Install express package

npm install express
yarn add express

Uninstall express package

npm uninstall express
yarn remove express

Install express package and save in devDependencies

npm install express --save-dev
yarn add express --dev

Upgrading all dependencies across the project

npm update
yarn up

Managing the package manager

Installing npm and Yarn

npm comes installed with Node, so you only need to upgrade its version periodically.

Yarn introduced a new concept of per-project installations in version 2. This ensures stable installs across environments but requires a few commands to set it up. Follow these steps to get the latest Yarn for your projects.

First, install Yarn globally (we are using npm to get the first instance of Yarn installed):

npm install -g yarn

From now on, remember to install Yarn on a per-project basis like this:

cd ~/path/to/project
yarn policies set-version berry # below v1.22
yarn set version berry          # on v1.22+

Check version of your package manager

npm -v
yarn -v

Update to the latest version of your package manager

npm install npm@latest -g
yarn set version latest

Powered by

Copyright 2019 - present