npm is the default package manager for Node.js. Facebook has long been developing an alternative package management solution called Yarn . Yarn seems to be slowly disappearing from the Github readmes as the standard solution and the stats on the official site show that only a fraction of the packages are carried out by Yarn. Nevertheless, it is worth thinking outside the box.
Yarn is fully compatible with existing package.json files - so you can use both solutions for existing projects without any problems. The commands of the two solutions differ only marginally. Here is a comparison of the most important commands:
Description | npm | Yarn |
Initialize | npm init | yarn init |
Update | npm install -g npm | yarn self-update |
Installing the package | npm install --save [name] | yarn add [name] |
Installing the package | npm install --save-dev [name] | yarn add --dev [name] |
Install package globally | npm install -g [name] | yarn global add [name] |
Install all packages | npm install | yarn install |
Update all packages | npm update | yarn upgrade |
Uninstalling a package | npm remove [name] | yarn remove [name] |
Yarn started with the aim of solving some of the weaknesses of npm. The most obvious difference is the higher performance: With incremental installations, multithreading and the latest killer feature Plug'n'Play (PNP) , performance increases dramatically. Plug'n'Play discards the idea of a project-based node_modules folder, the number of files that can often grow to astronomical heights . More information can be found in the official plug'n'play whitepaper. We install eslint once with npm and then with yarn with the cache warmed up in each case to make the difference in speed (6x!) Clear: