What are the differences between npm and Yarn?

10

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

Is there any considerable benefit between the two?

    
asked by anonymous 19.09.2017 / 14:17

2 answers

11

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

Yarn was born within facebook and due to some frustration that NPM iterate slowly and be slow. This came to be corrected, perhaps by influence of concurrence Yarn.

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

Differences in API:

           NPM  |  YARN

       npm init | yarn init
npm install ... | yarn add ...
 npm update ... | yarn upgrade ...
 npm remove ... | yarn remove ...
    
19.09.2017 / 14:24
5

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 be different from the actual dependency tree because the duplicate dependencies are merged. The npm client installs dependencies in the node_modules directory in a non-deterministic manner. This means that, based on the order in which dependencies are installed, the structure of a node_modules directory may be different from one person to another. These differences can cause "machine-running" errors that take a long time to discover.

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

Parallelization

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

Features

The network is used most efficiently by yarn . There is a global cache of each package that is downloaded, so you only download each package once. In addition, you can better use of other system resources (such as RAM) .

Fonts

  • When to use Yarn over NPM? What are the differences?
  • Yarn: A new package manager for JavaScript
  • README.md from the Yarn repository on GitHub
  • 19.09.2017 / 15:17