Get your JavaScript project started (with yarn and not npm)
Not an exhaustive guide, but more of a teaser
Published in
2 min readApr 11, 2017
No time? Here are the steps:
- Install npm — details here
- Install yarn — details here
- In a bash/command prompt window create a new directory and
cd
into it yarn init
- 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?
- npm — is mainly two things, a repository where you can search for (and publish) packages and the command line tool used to manage them
- yarn — is a command line tool created to address some of the shortcomings of npm (more on this below).
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:
- Cheat Sheet for yarn — https://yarnpkg.com/en/docs/usage
- Yarn workflow — https://yarnpkg.com/en/docs/yarn-workflow
- Migrating from npm — https://yarnpkg.com/lang/en/docs/migrating-from-npm/
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.