Share this article:

Blog
Sep 15, 20225 min read

NVM vs NPM vs Yarn

Ventsislav Venkov

Junior Developer

NVM vs NPM vs Yarn

Compared to the three technologies, NVM differs from the other two. Node Version Manager (NVM) is used to manage Node.js versions. NPM and Yarn are Node.js package managers. They allow downloading, installing, and managing packages when developing in JavaScript.

What is NVM?

As you already know, NVM is the Node Version Manager. It allows fast and convenient switching between different node versions for testing and developing an app.

Why use NVM?

NVM allows users to:
  • With a single command, you may locally download any remote Long Term Support (LTS) version of Node.js.
  • From the command line, you can quickly switch between different Node.js versions.
  • Create aliases to easily switch between different downloadable versions of Node.js.

Using NVM

If NVM is installed, you can manage any version of Node.js through a simple command.

This lists all installed local versions of Node:

nvm ls

To install a specific version, this command can be used:

nvm install <SPECIFIC_NODE_VERSION>

To use (or switch) a specific version of Node.js, use the following command:

nvm use <SPECIFIC_NODE_VERSION>

NPM vs Yarn

Node Package Manager (NPM)

NPM is the package manager by default for Node. Simple commands are supported because it is a CLI (Command Line Interface) installer. It has packages written in JSON and is open-source and cost-free. In a package.json file, the dependencies of your Node application can be listed and stored. Users can also distribute packages. The primary npm registry has more than 1.3 million packages. Automation of dependency and package management is the primary goal of NPM. Using a "package.json" file, npm may install all of a project's dependencies in a single command when used as a dependency manager for a local project.

Yarn (Yet Another Resource Negotiator)

The most latest and enhanced version of NPM is yarn. As a replacement for NPM, Facebook, Exponent, Google, and Tilde created it in 2016. It was designed to offer complex functionality that NPM was missing. To stabilise its use, NPM has added a few crucial functionalities. Yarn uses the same techniques as NPM, but it keeps track of all installation data internally to ensure compatibility across platforms. It is also more secure and stable than NPM.

The differences

Yarn caches all installed packages. Yarn installs the packages simultaneously, and that is why Yarn is faster than NPM.

They both download packages from the npm repository. Yarn generates yarn.lock to lock down the versions of the package's dependencies by default.

Yarn does a security check in the background when it downloads packages. In order to prevent downloading malicious scripts and cause dependency issues, it makes use of the package's license information. Security was a big worry for NPM in its early iterations. Since version 6, every time a package is installed, NPM performs a security audit. This ensures that there are no conflicting dependencies and helps to prevent vulnerabilities.

There are numerous fundamental similarities between Yarn and NPM:

  • Automatically generated lock files
  • Support for using Workspaces
  • Support for using remote scripts - npx vs yarn dlx
Recent changes to NPM and Yarn

Both Yarn and NPM are constantly being updated with bug fixes and new features like NPX and PnP.

NPX

Node Package Executor, abbreviated NPX. It's a feature introduced in NPM 5.2.0 and later. NPX facilitates the running of one-off instructions. Thanks to NPX, packages listed in the NPM registry may be run without being added as dependencies to your project.

In order to get familiar with NPX, read this manual.

Yarn2 (Berry)

With the release of Yarn2, also known as Berry, Yarn expanded their yarn line. Plug'n'Play, Constraints, Offline Installation, Zero-Installation, Workspaces, and Yarn Dlx are just some of the amazing new features in this edition of Yarn (the new Yarn NPX).

If you’ve done these steps described in this section correctly, you will see a new block in phpinfo().

Here are the most noteworthy enhancements:

Plug'n'Play is an alternate method of setup. Unlike Node.js, which creates a node modules directory and handles the resolution on its own, Plug'n'Play just generates one pnp.js file.

  • Eliminating node modules.
  • Package installation times have been cut by as much as 70%.
  • If you neglect to provide a dependency, Plug'n'Play will give you a warning.
  • Quicker startup of current projects.

If you want to find out more about Plug'n'Play, read this manual.

Project dependencies may be managed with the use of constraints, which let you to declare general rules in prologue (a declarative programming language). So long as there are no incompatible dependencies in your repository, you may set up rules to enforce them.

Modernized Workspaces - you may now set up a mono repository in order to control the interdependencies between several projects. Due to this, it is possible for many projects to refer to each other. Any changes made to one repository automatically update the others.

The two yarns, Yarn1 and Yarn2, are very unlike. Learn how to make the transition from Yarn1 to Yarn2 with the help of this handy tutorial.

In conclusion

There are big differences between NVM, NPM, and Yarn.

  • Node.JS can be set up with NVM.
  • NPM is the best way to install all of the packages you need.
  • Yarn works like NPM, but it is faster and more stable when installing and listing
  • dependencies for your Node.JS application.

What they have in common is that they are all used by Node applications.

At Bulcode we are used to dealing with both NPM and Yarn however the preferred choice is typically Yarn.

SUBSCRIBE TO OUR NEWSLETTER

Share this article:

SUBSCRIBE TO OUR NEWSLETTER

Related Blog Articles

    Why startups hesitate to work with a bespoke software development agency – and how we address every concern

    Blog

    Why startups hesitate to work with a bespoke software development agency – and how we address every concern

    Startups often hesitate to work with software agencies due to concerns over cost, control, and flexibility. Discover how Bulcode’s bespoke software solutions address each challenge, ensuring growth and agility.

    Written by Svetoslava Angelova
    Nov 05, 20245 min read
    Building a high-performing Agile team: Our proven approach

    Blog

    Building a high-performing Agile team: Our proven approach

    Discover how we build high-performing Agile teams by defining clear roles, fostering collaboration, and using flexible tools.

    Written by Svetoslava Angelova
    Aug 27, 20248 min read
    Drupal 11: What to expect? Comprehensive guide to new features and enhancements

    Blog

    Drupal 11: What to expect? Comprehensive guide to new features and enhancements

    Drupal 11 is out! In this article, discover it's exciting features and improvements. Upgrade now to redefine your digital strategy with Bulcode's expert support.

    Written by Svetoslava Angelova
    Aug 05, 20247 min read
    Single Directory Components in Drupal core: A comprehensive overview

    Blog

    Single Directory Components in Drupal core: A comprehensive overview

    Explore how Single Directory Components (SDC) in Drupal Core streamline the development process by encapsulating component-related files into a single directory. Learn about the benefits of SDCs and follow a step-by-step guide to implement them in your Drupal projects.

    Written by Nikolay Tsekov
    Aug 07, 20244 min read
    Scrum events

    Blog

    Scrum events

    Scrum defines several events (sometimes called ceremonies) that occur inside each sprint: sprint planning, daily scrum, sprint review, and sprint retrospective.

    Written by Svetoslava Angelova
    Nov 22, 20223 min read
    Scrum artefacts

    Blog

    Scrum artefacts

    In software development, the term “artefact” refers to information that stakeholders and the scrum team use to describe a product that’s being developed.

    Written by Svetoslava Angelova
    Nov 23, 20222 min read
    Headless Drupal with Next.js - simple example walkthrough

    Blog

    Headless Drupal with Next.js - simple example walkthrough

    The trend recently, in web development in general, and consequently in Drupal development is to use the technology headless. The trend recently, in web development in general, and consequently in Drupal development is to use the technology headless.

    Written by Mihail Shahov
    Jan 13, 20237 min read
    Hire dedicated software developers (teams)

    Blog

    Hire dedicated software developers (teams)

    Tired of raising expenses with your in-house development team? Why not get a dedicated team at 40% to 60% of the cost?

    Written by Mihail Shahov
    Jul 17, 20203 min read
    The importance of the right development partner in your software development life cycle

    Blog

    The importance of the right development partner in your software development life cycle

    Unlocking success: The art of choosing the perfect software development partner. Explore the pivotal role of partners in software development, uncover ROI secrets, and stay ahead of industry trends in this must-read article.

    Written by Mihail Shahov
    Sep 26, 20238 min read
    Config split module tutorial for Drupal

    Blog

    Config split module tutorial for Drupal

    Very often we as developers need to work with different environments. This could sometimes lead to (un)expected problems. In Drupal 8 we use the configuration system which works pretty nice, but there are cases where the settings for the local and any other environment should be different.

    Written by Ivaylo Tsandev
    May 20, 20217 min read
    Unveiling the power duo: Next.js as the Headless frontend of Drupal 10

    Blog

    Unveiling the power duo: Next.js as the Headless frontend of Drupal 10

    Discover the dynamic synergy between Drupal 10 and Next.js, as this powerful combination reshapes the landscape of web development. Next.js, an open-source React-based framework, is seamlessly integrated as the headless frontend of Drupal 10, offering a plethora of benefits. From enhanced performance with features like automatic code splitting and server-side rendering to flexible design and SEO-friendly capabilities, this collaboration empowers developers to create high-performing, scalable, and visually appealing web applications. The efficient content management of Drupal 10 coupled with Next.js' adaptability to trends ensures a cutting-edge development approach, positioning this tandem at the forefront of modern web development practices. Embrace the future with the Drupal 10 and Next.js combination, redefining how we approach and craft dynamic online experiences.

    Written by Todor Kolev
    Feb 07, 20245 min read
    Config ignore module tutorial for Drupal

    Blog

    Config ignore module tutorial for Drupal

    Sometimes we don't want our configurations to be shared in the codebase. So what can we do in such cases?

    Written by Ivaylo Tsandev
    Jul 27, 20217 min read

    GET IN TOUCH

    Have a project you'd like to launch?