w3resource

The yarn workflow and creating a new project


In this tutorial, we will look at the yarn workflow as well as how to create a new project.

Yarn workflow

When you introduce a package manager into your project, it introduces a new workflow around dependencies. Yarn will attempt to stay out of your way and make every step of the workflow simple enough for you to understand.

These are the few things you need to know about the basic workflow:

  1. Creating a new project
  2. Adding/updating/removing dependencies
  3. Installing/reinstalling your dependencies
  4. Working with version control (e.g. git)
  5. Continuous Integration

Creating a new project

Whether you are starting a completely new project or you have an existing repository, the addition of Yarn works exactly the same way.

All you need to do is to open the terminal in the directory that you want to add Yarn ( which is usually the root of your project) and then run the following command:

```yarn init```

Running the command above, will open up an interactive form for creating a new yarn project with the following questions:

```name (your-project):
version (1.0.0):
description:
entry point (index.js):
git repository:
author:
license (MIT):```

You can either type answers for each of these or you can select the default by hitting enter/return key.

package.json

Once you are done with answering the questions from the interactive form, you should have a package.json file in your directory that is similar to this:

```{
  "name": "my-new-project",
  "version": "1.0.0",
  "description": "My New Project description.",
  "main": "index.js",
  "repository": {
    "url": "https://example.com/your-username/my-new-project",
    "type": "git"
  },
  "author": "Your Name <[email protected]>",
  "license": "MIT"
}```

Whenever you run yarn init, the package.json file is the end product. There is nothing happening in the background, you can easily edit this files as much as you want.

Your package.json file will be used to store information about your project. This information includes the name of your project, the project maintainers, the repository of the project, but most importantly it contains information on the dependencies that needs to be installed for the project.

Previous: Troubleshooting
Next: Installing dependencies and working with version control



Follow us on Facebook and Twitter for latest update.