Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 986 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Yarn: A JavaScript Package Manager

1:57 JavaScript lesson by

Yarn is a new JavaScript package manager that aims to be speedy, deterministic, and secure. See how easy it is to drop yarn in where you were using npm before, and get faster, more reliable installs.


egghead.io comment guidelines

Avatar
egghead.io

Yarn is a new JavaScript package manager that aims to be speedy, deterministic, and secure. See how easy it is to drop yarn in where you were using npm before, and get faster, more reliable installs.

Yarn is a package manager for JavaScript. We can install it with the other package manager for JavaScript by typing, "npm install -g yarn." I've checked out the React source code. Let's use Yarn to install its dependencies. We can do that just by typing, "yarn."

It reads from the package.json file, so it should work on any project that's already using npm. It's pretty speedy too. It took about 12 seconds. With npm, it took almost two minutes. It puts its dependencies in Node modules, just like npm, so all your tooling should work the same.

Let's check out the getStatus to see what changed. Yarn added this yarn.lock file. What's that about? The yarn.lock file lists every dependency and the exact version of that dependency that was installed. This is what lets Yarn be reproducible and deterministic.

When Yarn installs from a yarn.lock file, it installs the exact same code everywhere. Let's add this to source control, so that our team can get the same dependencies that we have.

You know what React really needs is Backbone.js. Let's use Yarn to add Backbone, as a dependency, to React. We can do that by typing, "yarn add backbone." Let's check out the getStatus to see what has changed.

You can see that two files were modified, package.json and yarn.lock. Backbone was added as a dependency in package.json. Backbone and Underscore were both added to the yarn.lock file. That's because Backbone depends on Underscore.

Every dependency and all of the dependency's dependencies get added to the yarn.lock file. Let's commit this. Finish React. It's now complete.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?