Do IT Better and Faster with YARN. And Keep Calm

Yarn_openGeeksLab

For many years Facebook used one of the most popular package managers JavaScript which called NPM. This package provides access to more than 300 thousand packages; more than 5 million developers are using it.

In 2016 on the official blog of Facebook appeared information that Facebook find a worthy replacement for NPM. “We’ve used the npm client successfully at Facebook for years, but as the size of our codebase and the number of engineers grew, we ran into problems with consistency, security, and performance. After trying to solve for each issue as it came up, we set out to build a new solution to help us manage our dependencies more reliably. ” – this information was published in the official blog. So, Facebook and Google came together and created a more efficient tool to manage packages. This tool was named Yarn.

Yarn does not replace NPM, Yarn complements NPM. This is a new command-line client, which downloads the modules from the registry of NPM.

Don’t be afraid, in the registry nothing changes. 🙂

How to work with Yarn

As I said above Yarn does not replace NPM, it is more like a more improved NPM. Yarn use the same package.json file and retains the dependencies folder node_modules/. If you want try Yarn in work you can use package.json from any your project. For example:

Then create the working directory and put there your package.json file. To run the package installation run the command yarn or yarn install.

Commands in Yarn: adding, upgrading, and removing dependencies

  ● the command to adding a new dependency
 yarn add [package-name]
  ● the command to specific package version or tag
 yarn add [package]@[version]
  ● the command to updating and removing the package
 yarn upgrade [[package-name]
 yarn remove [[package-name]

Clearing dependencies from debris

It is problem when with packages we get unnecessary things. Yarn can help us with it. With command yarn clean Yarn will try to remove as much debris. After this command you can find new file .yarnclean.

Functional features of Yarn

Speed

Series of tasks runs during the installation of package. While in NPM tasks are performed sequentially and separately for each package, in Yarn these operations are performed in parallel, which improves performance. For example, if we will install express package with NPM and Yarn without using cache, shrinkwrap or lock files (42 files), we will get such result:

  • npm: 9 seconds
  • Yarn: 1.37 seconds

I think it’s really significant result and this example there is no doubt that the yarn is really cool.

Console logs

By default, NPM displays very much. Yarn isn’t verbose at all and uses emojis.
Other features of Yarn:

  • offline mode;
  • determinancy;
  • multiple registries;
  • network flexibility;
  • the presence of Flat Mode.

Conclusion
So, if you haven’t tried Yarn in your projects I strongly recommend to do it. Project will be better with Yarn. Thanks for attention and good luck!