Spoiler: You must go for Yarn! :)
Let me explain a bit about Node Package Manager(NPM) . We use Package manager to find and use existing code or libraries. Like we could install jQuery, React, Redux, VueJS, Vua-Redux anything from the package manager and it’s super easy. Just by writing.
npm i packageName --save
NPM also allows developers to upload their created libraries or code block.
Why Yarn, when we have NPM?
This is the burning question now. NPM works great for thousands of developers but it won’t work that great for companies like Facebook , Google. If you’ve deleted your node_modules folder for any reason and run ‘npm install’ in the project console, npm will re download each and every package along with their dependencies which is too much time killing. Yarn is great in this purpose. It caches every package it downloads. If you have ever downloaded the package before, you can install it in offline mode too.It also parallelizes operations to maximize resource utilization so install time are faster than ever, like the rocket trying to escape the earth’s gravity!
Yarn is super secured. It uses checksums to verify the integrity of every installed package before its code is executed.
Yarn is reliable . According to their voice, “ Yarn is able to guarantee that an install that worked on one system will work exactly the same way on any other system.”
Deep diving into Yarn:
If you had npm installed before and willing to check Yarn’s power, just simply run the command below.
npm install --global yarn
If you din’t have npm installed before, check there website documentation for more details. https://yarnpkg.com/en/docs/install
How to Yarn?
For the most of it, if you know NPM, you’re already set!
Let’s start with the most popular npm command ‘npm init’ that sure has a yarn option. That adds a ‘package.json’ file in the root of your project
npm init === yarn init
These are all the same:
npm link === yarn linknpm outdated === yarn outdatednpm publish === yarn publishnpm run === yarn runnpm cache clean === yarn cache cleannpm login === yarn loginnpm logout === yarn logoutnpm test === yarn test
‘Install’ is Yarn’s default behavior
npm install === yarn
The React Js library is saved in your package.json file:
npm install react --save === yarn add react
More ever Yarn has some great features that NPM don’t have. You can check the licenses of your dependencies and you can also generate your licence dependencies. Oliver Combe added a great tool ‘yarn why package-name’ , this will identify why this package is installed and which other packages are dependent over it. Let’s check the examples.
yarn licensesyarn licenses generateyarn why react
Yarn’s another great feature is, it automatically shrinkwrap with the yarn lockfile.
The one last thing we need to know, ‘Well Nothing :P’. Now, you know it all.
Hope we’ll have a great time with yarn. Cheers!