This is the 24th day of my participation in the August Text Challenge.More challenges in August

preface

I used NPM before, and then the company manager recommended another package management tool called YARN. After I used it, I found that YARN is really good compared to NPM. Let me summarize their common instructions and their differences.

The installation

To install YARN and NPM, you need to download node from the official website. To install node, enter node -v in CMD to print the node version.

Node is integrated with NPM, so node is installed, and NPM is installed with it.

For YARN, there are two modes

First, you can download the installation package from this address.

Alternatively, you can install NPM install -g YARN

Second, if command not found is displayed, add the bin directory of yarn to the system variable, restart CMD, and run the command again.

Directive contrast

Here are some common commands for comparison:

describe yarn npm
Initialization package. Json Yarn init (can be added later-ySkip the information asked) NPM init (can be added later-ySkip the information asked)
Install dependencies according to package.json Yarn install NPM install NPM installi)
Install a dependency (default is in Dependencies) Yarn Add packageName –save-S, or omit this parameter. NPM install packageName –save-S, or omit this parameter.
Install a dependency in devDependencies Yarn add packageName –dev-D) NPM install packageName –save-dev-D)
Global installation dependency yarn global add packageName npm install packageName -g
Remove reliance on yarn remove packageName npm uninstall packageNauninstallme
Removing global dependencies yarn global remove packageName npm packageName -g
Upgrade depend on Yarn Upgrade packageName (If it is a global dependency, add it to YARNglobal) NPM update packageName (if a global dependency is appended-g)
View dependency information yarn info packageName npm info packageName
Set Taobao Source yarn config set registry registry.npm.taobao.org yarn config set registry registry.npm.taobao.org
Viewing the Current Source yarn config get registry npm config get registry
List global dependencies yarn global list –depth=0 npm list -g –depth 0

The difference between

  1. Yarn is fast to install because it is an asynchronous dependency. NPM is executed synchronously and requires the previous package to be installed before it is installed.
  2. Yarn installation process information is very clean. NPM lists information about many other packages, which is not intuitive.
  3. After yarn is installed, there is a yarn.lock file, which locks the version you installed. When others install yarn, they directly read the yarn.lock file, which ensures that the versions dependent on the installation are the same. NPM also introduces this mechanism in 5.x.x. Its file is called package-lock.json.

conclusion

The above is my summary of YARN and NPM comparison, you can choose, I recommend yarn, hahaha.

Thank you for reading.