Overview
Yarn is a fast, reliable, and secure dependency management tool for JavaScript. Developed by Facebook, Yarn was created to address some of the shortcomings of NPM, such as speed and consistency in package installations.
Yarn uses a lockfile to ensure that dependencies are installed consistently across different environments.
Installation
There are multiple ways to install Yarn. In this guide, we will show the three easiest methods for installing Yarn. You can find information on other methods here.
Usage
Initializing a Project
This command initializes a new project and creates a package.json file.
Installing a Package
This command installs a package locally in your project and updates the package.json and yarn.lock files.
Example
This installs the lodash package, a utility library for JavaScript.
Installing a Package Globally
This command installs a package globally on your system, making it available from any directory.
Example
This installs create-react-app, a tool for creating React applications, globally.
Updating a Package
This command updates a package to the latest version. If no package name is specified, it updates all project dependencies.
Example
This updates the lodash package to its latest version.
Uninstalling a Package
This command removes a package from your project and updates the package.json and yarn.lock files accordingly.
Example
This uninstalls the lodash package.