Comparing Yarn and npm Node package managers
We strongly suggest using Yarn as a package manager.
Below is a comparison of key commands between npm and Yarn.
Starting a new project
npm init yarn init
Install all packages from package.json
npm install yarn
npm install express yarn add express
npm uninstall express yarn remove express
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
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