This is the second day of my participation in wen Challenge

What is NPM?

A command line tool, NPM has been relied upon by over 11 million developers worldwide – with over a million software packages, it is the largest software registry in the world. It can also be visually understood as an app store, where we can download all kinds of code that has been written, such as commonly used jQuery, WebPack and so on. The website links

The installation of NPM

  • npmisNode.jsNPM is installed by default in the default software package management system after Node is installed

After the installation is complete, use the CMD console (win + R), run the node -v command to check the node version, and run the NPM -v command to check the NPM version

  • Using the commandnpm i npm -gGlobal installationnpm, the latest version is updated by default

Basic use of NPM

  • NPM -v: Run == to view the version == and check whether the NPM is successfully installed

  • NPM install

    : Use the NPM command == to install the Module ==, for example, NPM install jquery

  • NPM uninstall

    : Use the command == to uninstall the Module ==, such as NPM uninstall jquery

  • NPM update

    : Update the Module == with the command ==, such as NPM update jquery

  • NPM install

    -g: can be used directly on the command line, installed on the == global ==

  • NPM list -g: View all globally installed modules

  • NPM list vue: Displays the == version number of a module

  • NPM -g install [email protected] :(@ followed by version number) so that we can update the NPM version, == specify the installed version number ==

  • NPM install -save moduleName: -save Write dependencies to the dependencies node of the package file. The default value

  • NPM install-save-dev moduleName: -save-dev Writes dependencies to devDependencies in package

  • Dependencies: == Dependencies: ==

  • DevDependencies: == dependencies of == The module is for development, not for release.

NPM image setup and view

View the image configuration result: NPM config get Registry

Sets the NPM to taobao mirror: NPM config set registry https://registry.npm.taobao.org – global

Use the NRM tool to switch to taobao: NPX NRM use Taobao

Switch to the official source: NPX NRM use NPM

Package.json property description

  • Name: indicates the package name.

  • Version: indicates the package version number.

  • Description: indicates the description of the package.

  • Homepage: indicates the official url of the package.

  • Author: indicates the author name of the package.

  • Dependencies: List of dependent packages

  • Repository: Type of place where package code is stored.

  • Main: The main field specifies the program’s main entry file, which requires (‘moduleName’) loads.

  • Keywords: keywords

Note:

The description of the version number in the package.json file means different things when installing:

“7.14.0” indicates the installation of the specified version 7.14.0

“~7.14.0” indicates to install the latest version of 7.0.x

“^7.14.0” indicates to install the latest version of 7.x.x

NPM install will install all dependencies in package.json directly if only the package.json file is copied

yarn

Yarn addresses some of the flaws of NPM!

Yarn installation

This is easy with NPM in mind

  • usenpmThe installationnpm install -g yarnView version:yarn --version

Taobao source installation:

Run the following two lines:

  • yarn config set registry https://registry.npm.taobao.org -g
  • yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g

Successful tip: success Set “registry” to “https://registry.npm.taobao.org”.

Basic use of YARN

  • Yarn init: Initialize the project like NPM init. After the input information is executed, the package.json file is generated

  • Yarn install: Installs all packages in package.json and saves the package and all its dependencies to yarn.lock

  • Yarn install –flat: Installs a single version of a package

  • Yarn install –force: Forcibly downloads all packages again

  • Yarn install –production: Install only the package described in Dependencies

  • Yarn install –no-lockfile: does not read or generate yarn.lock

  • Yarn install –pure-lockfile: yarn.lock is not generated

  • Yarn add [package] : Add a dependency package to the current project, which is automatically updated to package.json and yarn.lock files

  • Yarn add [package]@[version] : Installs the specified version. This version refers to the major version. If you need to specify the minor version, use -e

  • Yarn add [package]@[tag] : install a tag (such as beta,next or latest)

  • Yarn add –dev/ -d: add to devDependencies

  • Yarn add –peer/ -p: Add peerDependencies

  • Yarn add –optional/ -o: Add to optionalDependencies

The advantages of the yarn

  1. Speed is fast
  2. Unified Installation version
  3. Cleaner output
  4. Multiple registration source processing
  5. Better semantics