Yarn VS NPM
Here we go! Yarn and NPM are both package managers. What is a package? A package is a file or set of files containing pre-existing and reusable code. Packages can also be considered dependencies, as in an application could depend on a package to properly function. A package manager helps manage all of those packages. As an application/program grows over time. These package managers help include, exclude and update packages that will help the program function.
Let’s start with NPM. Node Package Manager (NPM) is a manager for JavaScript, its the default manager. It consists of command-line client and an online database. Command-line client is a cross platform that a client can use to access a server. Also, the online database consists of public free and paid packages to choose from.
Now, we can also use YARN, Yet Another Resources Negotiator. It’s a package manager that was created by Facebook and made it open to the public. It was mainly created to provide extra security when downloading and using packages.
The main differences:
- Yarn provides extra security opposed to NPM. NPM can add new files to the dependencies if needed. Yarn only uses what is inside the lock file.
- When comparing Yarn and NPM with regards to downloads, Yarn 2 times faster than NPM. Yarn can download and reads packages simultaneously, while NPM reads sequentially waiting for each one to download before going to the next.
- There is another package manager, “Bower”, that yarn can download packages from, so YARN can download from both nodejs and Bower.
- Currently Yarn can merge lock files easily, npm will create the another package lock file, with the same packages in it. So each package lock file will contain a different version, both will have the same files that were first used, but only the second will include the extra packages in it.
- The output in your terminal is very different.
- Licenses for packages can be seen with Yarn, NPM doesn’t really show them.
- NPM is downloaded automatically when you install Node. To install yarn you can use:
There are many more features that YARN has over NPM.
https://www.ryadel.com/en/yarn-vs-npm-pnpm-2019/
But wait! There is a third one! PNPM. PNPM (Performant NPM) was created not too long ago. It supposed to be 2 times faster than yarn. The new idea that makes PNPM so much faster, is because it can store the package files inside of your memory for instant access. https://pnpm.js.org/en/
Here is a comparison of the NPM, YARN, and PNPM: https://rushjs.io/pages/maintainer/package_managers/
At a personal experience, NPM is honestly much slower than YARN. The output of Yarn is also much more easier to read. I do plan on installing PNPM and trying out it’s speed.