DEV Community

Madza
Madza

Posted on

NPM vs Yarn: which package manager do you use?

Two popular package managers in the ecosystem are NPM (Node package manager) and Yarn (package manager created by Facebook).

Which one do you use and why do you prefer it over the other?

Top comments (22)

Collapse
 
gndclouds profile image
William Felker

When I started learning to code, I liked Yarn over NPM because it felt like it exposed more of what was happening in the background in a more digestible way.

It would be interesting to know what some of the fundamental differences are tho.

Collapse
 
ehsan profile image
Ehsan Azizi • Edited

For me doesn't really matter which one to use as long as the real problem exists which is the node_modules folder, unfortunately after over a decade of NodeJs this problem still isn't fixed, why should I have more than 30k of dependency files for every simple Create-React-App app, why there is not a centralized dependency management solution like C#, Currently I have a few React and Angular projects and the size of node_modules folders are almost 5GB and millions of files, I know there are some solution for this like PNPM but they are not without problems and also not as straight forward.

Collapse
 
andrewbaisden profile image
Andrew Baisden

My preference is to use npm because I have never really experienced that many problems with it. I have used yarn a few times and it feels like its almost exactly the same as npm. And because npm seems to have more usage I have just stuck with it for now. Unless I can see some real significant performance gains they seem to be more a less the same. It is like comparing React to Angular its just two different ways of doing the same thing.

Collapse
 
al5ina5 profile image
Sebastian Alsina • Edited

This was exactly what I thought until I used yarn. Most of the tutorials and open source projects online use npm in their installations guides, so I assumed it was better. I now use yarn always because it’s much speedier and has nicer output.

Collapse
 
rodbove profile image
Rodrigo Mello

I only use Yarn because of recommendations I received regarding speed, and I really saw some difference there. But honestly never had any problem with NPM and the projects I started on NPM I kept it. If anyone could share a source with a bit more details on how each really differ from the other I'd appreciate.

Collapse
 
midblue profile image
Jasper Stephenson • Edited

Phew, I didn't know Facebook made Yarn. That makes me way less interested in using it, honestly.

I tend to use NPM just because my bash shortcuts are already set up for it, i.e. "d" for "npm run dev".

I guess it's mostly laziness, but all of my old projects already have package.json scripts that use npm so it seems silly to try to change for marginal speed benefits.

Collapse
 
abinash393 profile image
Abinash Panda

Facebook made React, React Native, GraphQL, and so on. I don't like Microsoft but can't live without VS code, Github, NPM.

Collapse
 
_hs_ profile image
HS

Well Microsoft didn't MAKE Github nor NPM they jus bought it (github an so npm becomes part of it) so I'm not sure if it counts for that matter. Anyways too many people moved to GitLab and after experiencing some issues on Github I know why except for the fact they dislike MS. They do influence development of it so it might count.

As mentioned people still move away after such events but does it count as it would if they "made" it? For comparison Android was not made by Google but after buying it they controlled everyting (just my perspective of it might be incorrect), but MS didn't say they will write some Ruby to change the Github so does it really count?

Thread Thread
 
abinash393 profile image
Abinash Panda

Your perspective is right they acquired other companies because that will make more profit to their ecosystem.

Developers don't have a trust issue with Apple even though their products are closed source and then don't even contribute anything. And Microsoft has contributed to Linux kernel so any way we are going to have to use it. I believe its good if it's opensource.

Anyway, Competition is good npm is the best of itself because of yarn (caching and security).

Collapse
 
bgrgndzz profile image
Buğra Gündüz

Facebook has a lot of great open source projects, and great minds behind them! Why did it make you less interested?

Collapse
 
_hs_ profile image
HS

Trust issues I would guess. Although it's open source it might contain code which you morally disapprove. Example: some people get the base code of VS Code(forgot the name)
then build it themselves which is different from what you get if you install their /MS version.

Thread Thread
 
al5ina5 profile image
Sebastian Alsina

Would you mind elaborating? This is interesting. What code does VS Code have that is morally questionable?

Thread Thread
 
_hs_ profile image
HS • Edited

You'll have to research for more details but in short, if you download "binaries" you'll get stuff that measures metrics and such and sends them back to MS, which I'm not sure is morally bad sice you click that agree. You have multiple posts of this one.

Collapse
 
markel profile image
Markel F.

I admit I've never used Yarn, NPM has always had all the features I've ever needed, although I admit I'm not a professional developer

Collapse
 
axelledrouge profile image
AxelleDRouge

I have recently tried yarn and liked it mostly for its speed and for its clear explanations of what is happening

Collapse
 
nolyoi profile image
Nolan Mayersky

I prefer Yarn. Not sure why tbh. Feels a little cleaner to me. But I bounce between the two.

Collapse
 
al5ina5 profile image
Sebastian Alsina • Edited

Yarn! It's way faster and has much prettier output.

Collapse
 
pavelloz profile image
PaweΕ‚ Kowalski

npm. Because it works.

Collapse
 
easrng profile image
easrng

I use npm because I'm lazy, but i reccomend pnpm.

Collapse
 
gsin11 profile image
Gurpreet Singh

I am using it in my current project where we also implemented yarn workspaces, which is quite easy to maintain with yarn instead using it through npm.

Collapse
 
awesomeironman profile image
Cyrus Gracias

I prefer yarn over npm because of the performance benefits
Performance while installing packages
As well as
Its commands are shorter, take less keystrokes to run

Collapse
 
ducdev profile image
Duc Le

Yarn workspace is the game changer for monorepo.