Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Yarn: A JavaScript Package Manager

    Jamison DanceJamison Dance

    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.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.