npm

Yarn or npm: What's your preferred package manager?

NPM & Yarn have a lot to offer. But its always tough to choose right one; & becomes more tough when working in a team. Here are my opinions on this delima.

Yarn or npm: What's your preferred package manager?

In the FrontEnd space, yarn and npm are very commonly know names as the package managers.

Though I have a question for you, what do prefer to use among them?


Package Managers

Package Managers are responsible for the package information and dependency management for any project. If you are familiar with other programming languages, following names are the commonly used package managers there:

  • PHP: composer
  • JavaScript: npm and yarn
  • Java: Maven and Gradle
  • Python: pip
  • ASP.NET: NuGet
  • etc.

Node Package Manager (npm)

NPM is the default package manager which comes shipped with Node.js. It has evolved a lot over time along with Node.js and offered many features either with innovation or competition.

Yarn

Yarn is a package manager built by folks at Facebook to overcome some initial problems of npm. Yarn is the first package manager to introduce lock file for deterministic resolution of packages.


There are so many comparisons of NPM and Yarn on the internet, and they provide enough argument to help in choosing the primary package manager.

I wanted to discuss specifically about the lock files generated by both package managers.

Over the time, my preferences changes for JS Package Mangers as:

  1. I started preferring Yarn because of Lock file yarn.lock
  2. Moved back to NPM as Lock file package-lock.json was introduced
  3. Feel like moving back to Yarn as it can offer more on top of basic npm

My Reasons:

  • Another Package manager?
    I stopped using yarn because of the need to have one more package manager, which means you needed to install yarn as a global dependency first on newer setup or CI/CD and then use Yarn.
  • Integrity Hashes:
    Integrity Hashes in package-lock.json keep changing based on your Node.js and NPM version. As newer versions of npm use strong SHA algorithm as compared to the older ones; this introduces so many continuous unwanted changes in package-lock.json
  • CI/CDs might have Yarn installed by default:
    You can use Docker images which already have Yarn installed by default and save time during the installation.
  • Speed:
    Yarn is a way faster than NPM (I am not making any claims here; I felt that yarn is faster and that's why I am stating that. There are many Install Time comparisons of NPM and Yarn like this one: https://github.com/appleboy/npm-vs-yarn)
  • Some Added Features:
    Features like Workspaces, Plug-and-Play (PnP) etc. can be leveraged to have better development experience with Yarn.

Conclusion

Both package managers have a lot to offer. Though it is always a dilemma to choose the right one for any project.

This becomes more tough choice when working in a team.

I leave you with some questions:

  • What is your preferred package manager?
  • Why and how did you reach this conclusion?

Let me know through comments 💬 or on Twitter at  @patel_pankaj_  and/or  @time2hack

If you find this article helpful, please share it with others 🗣

Subscribe to the blog to receive new posts right to your inbox.


Credits

You've successfully subscribed to Time to Hack!
Close