Get your JavaScript project started (with yarn and not npm)

Not an exhaustive guide, but more of a teaser

No time? Here are the steps:

  1. Install npm — details here
  2. Install yarn — details here
  3. In a bash/command prompt window create a new directory and cd into it
  4. yarn init
  5. Enter a name for the project and version (required) and fill out the rest of the details (optional).

Do I have to? When would I use it?

You don’t have to, but you will want to if you are doing web, node, mobile (with React Native), and possibly other JavaScript based development.

WTF is a package vs. a module?

When you “start a project” with yarn, you technically create a package.

  • Package — in its simplest form it is a folder containing a program described by a package.json file.
  • Module — anything that can be loaded with require() in a Node.js program

Most packages in npm are modules.

WTF in nmp and yarn?

OK, what do I get?

By creating a project using npm or yarn (I vote for yarn) you get the following:

  • Easy access to over 340,000 packages — so that you don’t have to reinvent the wheel.
  • Modules stay out of your source code — this is particularly relevant when using source control like Git, SVN, etc. When you download your code, just run the yarn command and all the packages are quickly downloaded to the right version.
  • Package management on your terms — all dependencies are tracked in a package.json file with specific versions and you can control when to upgrade.
  • Script common tasks — you can easily automate common tasks like starting you server.

Why yarn and not npm?

Yarn addresses some of the shortcomings of npm. Mainly:

  • Offline Workflow— There is no need for an internet connection if you have already installed a package.
  • Faster Downloads — The downloads are parallelized making install of packages significantly faster and retried if there is some failure.
  • Avoids Duplicate Versions— If you have dependencies with mismatching versions they will get resolved to a single version.

OK, what do I do now?

Check out the following guides:

Like this article? Press the heart below and share it! Know a better way to do things or just want to say hi? Great! I love learning new and better ways :) Write me at hey at itsmeeric.com.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.