NPM vs Yarn

Stacey Carrillo
3 min readMar 22, 2021

--

As an aspiring web developer I have used and heard of NPM and Yarn, but what are they, and what are they even used for? As we head down this educational journey together we’ll answer a few of these questions to get a better understanding of why we should use each and when?

What Is NPM?

NPM stands for Node Package Manager. It is an online repository where developers can publish open-source Node.js projects. It is also a command-line utility that is used to download and install software for free. The npm website can be used to discover packages.

One of the many benefits of npm is the ability to run packages without having to download them by using npx. Npm provides developers with the ability to share code publicly, or privately with teams and organization options.

What Is Yarn?

In its truest definition Yarn is just a package manager for your code. It gives developers the ability to easily share code all around the world but how does it accomplish this?

What Yarn Brings to the Table

The first characteristic of Yarn that we can look at is its speed. Yarn stores every package in a global cache (a collection of items of the same type stored in a hidden or inaccessible place) so it’s never necessary to download them again. Yarn also executes its processes so that they are carried out simultaneously adding to its speed.

Yarn also uses checksums (often used to verify data integrity but are not relied upon to verify data authenticity) to verify every installed package before its code is executed.

On top of its speed and security Yarn uses a concise and detailed lockfile format coupled with a deterministic algorithm for all installations that guarantees that an installation that worked on one system will work the exact same way on another.

Yarn allows users to install a package offline if they’ve installed it in the past. In addition, Yarn’s network efficiency is great as a request will be attempted again if it fails which prevents an entire installation from failing.

Last but not least, Yarn has what is referred to as Flat Mode. This allows Yarn to resolve a mismatched version of dependencies and reduces them into a single version.

NPM vs Yarn

Both seem similar when compared but in reality, Yarn is used with npm to solve a few problems. Installing packages with npm can be slow and inconsistent, with yarn speed is improved.

In addition, npm allows packages to run code on installation and Yarn provides that extra layer of protection needed. But as mentioned before Yarn brings many benefits when used and can be a powerful tool when coupled with npm. In the end, one must come to their own conclusion and work with whichever tool will be the best.

Sources

--

--

Stacey Carrillo
Stacey Carrillo

Written by Stacey Carrillo

Software Engineering Student at Flatiron School! Recently graduated as a Programming & Software Development Major at LaGuardia Community College.

No responses yet