Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Is Yarn package manager the successor of npm?

Friday, September 29th, 2017 by Servage

yarnNpm has been the most popular package manager for JavaScript with little competition for years. Starting from 2016, an alternative called Yarn has become more and more popular for managing dependencies in JavaScript projects. How is Yarn different, what can it do and is it better than npm?

The Benefits of Using Yarn

Probably the biggest advantage of Yarn is that existing projects using npm work with Yarn out of the box. If your project has a composer.json file with dependencies inside, you can use Yarn to install them.

Another benefit of Yarn is its speed and performance. In almost all cases, it installs your dependencies to the node_modules directory faster than npm. It also caches packages to make sure you don’t have to download the same package multiple times. You can also install dependencies without an Internet connection if the packages have been cached earlier. If you have an active Internet connection but the connection is not stable enough, Yarn will retry to download failed packages instead of canceling the installation process.

Yarn also takes advantage of threading to perform multiple operations at the same time to further increase performance.

Using Yarn

Npm is easy to use, but Yarn is possibly even easier. To get started, you need to install Yarn. There are many ways to install it. You can download download an installer package for your operating system or you can install it using npm: “(sudo) npm install -g yarn”. Make sure to use the -g parameter to install it globally.

To download the dependencies of your project to the node_modules directory, simply run “yarn” inside the root directory of your project where your package.json is located. You can also use “yarn install” if you are used to run “npm install”.

To create a new NodeJS- and npm-powered project, you can use “yarn init”. As you can probably guess, this does the same as “npm init”. When you run the command, Yarn will ask you a few questions related to your project like a project name, description and version.

To install new dependencies, use “yarn add <package>” where package is the name of a package from, for example “yarn add tether”. This is the equivalent to “npm install –save <package>”. The package is automatically added to the dependencies of package.json.

The “yarn upgrade <package>” will upgrade a package to the latest version. To remove packages, use “yarn remove <package>”.

As you can see, Yarn is an incredibly simple tool but provides the same features and even some benefits over npm. Which you want to use is up to you, and you can even use both in the same project with some small limitations (e.g. npm does not read the lock file of Yarn). Npm is still the more popular choice, although Yarn is expected to become more popular in the future.

Is Yarn package manager the successor of npm?, 5.0 out of 5 based on 1 rating
Categories: Software & Webapps


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet (leave a comment)

You are welcome to initiate a conversation about this blog entry.

Leave a comment

You must be logged in to post a comment.