DEV Community

Sewvandi Promodya Wickramasinghe
Sewvandi Promodya Wickramasinghe

Posted on • Updated on

Npm over Yarn

Both npm and yarn are package managers. As an alternative to npm, yarn was built by Facebook. They developed yarn to solve the problems they had when using npm, specifically the issues of accuracy, protection and speed. Within this article we'll look at npm and yarn differences. If there are any issues feel free to comment below and share your thoughts.

npm, the Node package manager

Alt Text
Npm is the default package manager we all know, and it is bundled with node.js. It is the command-line interface to the npm ecosystem. It is designed for battle-tested, incredibly flexible and uses JavaScript developers every day by hundreds of thousands.

npm install

Using npm -v you will see the current npm version which you are using.

Here's mine
Alt Text

If you have an older version of npm then you can update it to the latest version using the following command.

npm install npm -g
Enter fullscreen mode Exit fullscreen mode

To access npm help, use npm help in the terminal.

npm help
Enter fullscreen mode Exit fullscreen mode

new npm alternative, Yarn package manager

Alt Text

Yarn caches every package that it installs, so that it never has to do so again. This also incorporates activities to optimize resource utilization and installation times are quicker than ever before.

If you have npm installed, you can just install yarn with npm.

npm install yarn --global
Enter fullscreen mode Exit fullscreen mode

What differs yarn from npm?

Yarn is somewhat distinct from npm. The key reason developers choose to move to yarn is its stability. Firstly, yarn caches all the packages installed. Yarn is more convenient than npm. This is because yarn installs that packages at once in comparison with npm that installs one at a time. In npm, the versions of the installed packages can be different when we need to deploy the project on different machines. I assume this was the reason yarn first appeared. Yarn has an engaged community of users.

Both npm and yarn download packages from npm repository. Npm will run code from dependencies automatically. While this feature has its own accessability, it has raised several security issues. Yarn only installs from your yarn.lock or package.json files. Yarn.lock ensures that all users have the same software installed. It reduces the ability for bugs to be found in different versions.

Any yarn problems?

Yes, Unfortunately :(

Here are two major issues.

1)Installation of native modules is difficult.
2)Yarn doesn’t work with any node.js version older than 5.

Which one would you select?

yarn or npm?

There are many improvements yarn has higher speeds and more control over npm. But many people suggest that if you already know npm, a move to yarn isn't really necessary. To sum-up personally I will favor to use npm :)

Top comments (2)

Collapse
 
madza profile image
Madza

"if you already know npm, a move to yarn isn't really necessary"
agree with this ^^^

Collapse
 
sewvandiii profile image
Sewvandi Promodya Wickramasinghe

Yes. Even yarn is fast I still prefer npm πŸ₯³