What are the differences between npm and Yarn?

Asked

Viewed 5,966 times

15

I’m thinking of migrating from npm to the Yarn, can anyone tell me what the main differences?

Is there any considerable benefit between the two?

2 answers

17


Yarn and NPM are package managers, who fulfill basically the same mission.

The Yarn was born inside facebook and due to some frustration that NPM is slowly iterating and slowing down. This came to be corrected, perhaps by influence of Yarn concurrence.

For a more exhaustive comparison we would have to compare version to version of NPM and Yarn. But basically do the same, and (for now) are compatible because both use the package.json as a source of information what packages and versions the project needs. But beware: how they both write (and delete) packages/programs from the directory node_modules may happen that one installs/deletes specific versions that the other installed/removed.

Differences in the API:

           NPM  |  YARN

       npm init | yarn init
npm install ... | yarn add ...
 npm update ... | yarn upgrade ...
 npm remove ... | yarn remove ...

6

Some points that I consider important.

Determinism

In the Node ecosystem, dependencies are placed inside a directory called node_modules in your project. However, this file structure may differ from the actual dependency tree, as duplicate dependencies are merged. The client npm installs dependencies in the directory node_modules so nondeterministic. This means that, based on the order in which the dependencies are installed, the structure of a directory node_modules can be different from one person to another. These differences can cause "works on the machine" errors that take a long time to be discovered.

With yarn, you always know you are getting the same content on every development machine. yarn uses lockfiles and an installation algorithm that is deterministic and reliable. These lockfiles blocks the dependencies installed in a specific version, ensuring that each installation results in the same file structure in node_modules on all machines.

Parallelization

yarn is able to parallelize operations, maximizing resource utilization and making the installation process faster.

Resources

The network is used most efficiently by yarn. There is a global caching of each package that is downloaded, so you only download each package once. Also, it is possible to do better use of other system resources (such as RAM).

Sources

  1. When to use Yarn over NPM? What are the Differences?
  2. Yarn: A new package manager for Javascript
  3. README.Md from the Yarn repository on Github

Browser other questions tagged

You are not signed in. Login or sign up in order to post.