Home >Web Front-end >JS Tutorial >A brief analysis of the usage of Node.js package management tools npm and yarn

A brief analysis of the usage of Node.js package management tools npm and yarn

青灯夜游
青灯夜游forward
2021-08-19 10:05:231978browse

This article will introduce you to Node.jsHow to use the package management tools npm and yarn, and help you quickly get started with npm and yarn.

A brief analysis of the usage of Node.js package management tools npm and yarn

This article learns the use of the package management tool npm& yarn of node.js . [Recommended learning: "nodejs Tutorial"]

Use npm Shared projects:

npm official website: npmjs.com

Register an account on npm.js:

1. Use npm

  • Step one: First register an account on the official website
  • Step two: Verify the email address of the account
  • Step three: Save it Account and password

2. Turn the node project into a package

npm init Requires package name It must be the only one in the entire network

3. Upload the node package

npm adduser

4. Transfer the local package to the online warehouse

npm publish

##5 , Download the online node package npm install package name npm i lichune201807091415

Install Taobao image:

npm install -g cnpm --registry=https://registry.npm. taobao.org (Understand)

Then change

npm to cnpm to

install plug-ins in batches:

npm install will automatically go to the dependencies of the package.json package to find the difference between the plug-in name

dependencies and devDependencies?

    Use npm install node_module --save to automatically update the dependencies field value; Default
  • Use npm install node_module --save-dev to automatically update the devDependencies field value;
  • dependencie configuration Other packages that the current program depends on. Package management that online mode depends on (production mode)
  • devDependency Configure other packages that the current program depends on. Only the modules will be downloaded, but the testing and documentation frameworks of these modules will not be downloaded. Packages that development mode depends on

Small disadvantages of npm

    The package is downloaded synchronously
  • A project is downloaded once and re-downloaded in another project

Getting started with Yarn

Yarn documentation & download and installation

Yarn Yes One command is a wrapper for the npm command

Installation command:

npm install yarn -g

##yarn<span style="font-size: 16px;"></span> Usage:

    1. Create a yarn directory
  • 2. Execute
  • yarn init

    , enter the name of the package and press Enter. Use yarn to turn the code into a package (npm init)

    and pass it online:
      yarn login
    • ==== npm adduser yarn publish === npm publish
  • 3. Yarn add cheerio downloads the third-party plug-in package and comes with the --save feature. npm install cheerio --save ==== yarn add cheerio npm install cheerio --save-dev == yarn add cheerio --dev
  • 4、
  • yarn install

    ==== npm install Batch install all plug-ins in package.json

  • 5,
  • yarn update dependent package name

    Update a dependent package

  • 6.
  • yarn remove dependent package name

    The benefits of deleting a dependent package

##yarn<span style="font-size: 16px;"> : </span>

yarn
    is asynchronous and is faster to install than
  • npmyarn
  • It can effectively ensure that the version number is consistent. It is not prone to errors during development.
  • yarn
  • The local installed packages will be cached. It will be very difficult to directly call the packages in the cache when installing in other projects. For more programming related knowledge, please visit:
  • Programming Video! !

The above is the detailed content of A brief analysis of the usage of Node.js package management tools npm and yarn. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:掘金--iwin621. If there is any infringement, please contact admin@php.cn delete