Understand YARN, NPM and NVM

Hank
2 min readNov 16, 2019

--

NVM is a node.js version manager. It provides easy installation, switching between versions and retains globally installed packages for each version. NPM is a package manager, which help you install libraries, plugins, frameworks and applications.

Yarn is another package manager to automate the process of installing, upgrading or removing software. It also allows developer to use and share code with other developers. Code is share through something called a package. A package contains all the code being share as a package.json file.

Before using Yarn, you need to install it on your System. Here is an example install it on Mac OS with Homebrew. This will also installed Node.js if it is not installed.

install yarn through homebrew package manager

If Yarn is not found in your PATH, add this to you profile: export PATH=”$PATH:/opt/yarn-[version]/bin” (the path may vary depending on where you extracted Yarn to). Your profile may be in your .profile, .bash_profile, .bashrc or .zshrc. After you have Yarn installed, you can test the following most common commands.

Starting a new Project: yarn init

Adding a dependency:

Upgrading a dependency:

Removing a dependency: yarn remove [package]

To upgrade Yarn, you can use Homebrew. Type in “brew upgrade yarn” in your terminal. To verify your Yarn installed version, type in “ yarn — version”.

Another reasaon Facebook developed Yarn is security issues. Yarn only installs from your yarn.lock or package.json files. Yarn.lock ensures that the same packages is install throughout all devices, this reduces the chances of bugs from having different versions installed. Yarn can also run offline to install packages if you have already install them in the past.

Hope this will help you choose using Yarn, NPM or NVM during your work. I will keep updating this article and welcome suggestions and comments.

Note: Node.js is build on the V8 Javascript runtime. Each browser, Firefox, Safari or Chrome, has a Javascript engine built in it to process Javascript files in websites. Google Chrome uses V8 engine and Node.js uses the same engine to interpret Javascript files.

--

--