What is the equivalent of "npm install <package_name> --save" in Yarn?

NpmYarnpkg

Npm Problem Overview


I am using Yarn to install the dependencies of my project. What is the equivalent of "npm install --save " in Yarn to update the entry in my package.json file? I can use "npm install --save " here, but I want to use Yarn as much as possible to improve performance and avoid confusion between npm and Yarn.

Npm Solutions


Solution 1 - Npm

The yarn equivalent tonpm install <name> --save is:

yarn add <name>

Here's the link to the docs for the full list of commands in comparison to npm.

Solution 2 - Npm

Using --dev or -D will install one or more packages in your devDependencies.

yarn add <package...> [--dev/-D]

Yarn add documentation

Solution 3 - Npm

Use the following command :

yarn add [package_name]

Comparing npm and Yarn Commands

Install dependencies

npm install => yarn 

Install a package

npm install [package_name] => yarn add [package_name]

Install a package globally

npm install -g [package_name] => yarn global add [package_name]

Install a package as a development dependency

npm install --save-dev [package_name] => yarn add --dev [package_name]

Uninstall a package

npm uninstall [package_name] => yarn remove [package_name]

Uninstall a package globally

npm uninstall -g [package_name] => yarn global remove [package_name]

Uninstall a development dependency package

npm uninstall --save-dev [package_name] => yarn remove [package_name]

Update the dependencies

npm update => yarn upgrade 

Update a package

npm update [package_name] => yarn upgrade [package_name]

Create a new package

npm init => yarn init

Run a script defined in the package.json

npm run => yarn run

Test a package

npm test => yarn test

Publish a package

npm publish => yarn publish

Remove all data from the cache

npm cache clean => yarn cache clean

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionManivannanView Question on Stackoverflow
Solution 1 - NpmgaldinView Answer on Stackoverflow
Solution 2 - NpmLucas MatosView Answer on Stackoverflow
Solution 3 - NpmAbolfazlRView Answer on Stackoverflow