NPM base uses collation

0. Mind mapping

1. Initialization

NPM (Node package management tool) is installed with Node, so there is no need to install it separately

1.1 Customizing Initialization Information

npm init
Copy the code

1.2 Initialize the project using the default information

npm init -y
Copy the code

2. Module installation mode

2.1 Local Installation (Partial Installation)

  • Install the JS library in the directory where the current command is executed
NPM install <Moudle Name>Copy the code

2.2 Global Installation

  • Install the JS library in the global directory
NPM config set prefix 'D:\ NPM '# Change the default global installation directoryCopy the code
  • Install js modules globally
NPM install <Module Name>[@ version number] -gCopy the code
  • View globally installed modules
npm list -g
Copy the code

2.3 Installing production Environment Modules

  • The production environment module will be packaged into our project code
    • — save or -s
    • Save the module version information in the Dependencies field in the package.json file (production environment dependencies)

2.4 Installation of development environment modules

  • The development environment modules will not be packaged into our project code
    • – save – dev or – D
    • Save the module version information in the devDependencies field of the package.json file (development environment dependency)

3. Representation of the module version number

3.1 Specifying the version number

  • Only the specified version is installed
  • Major version. Minor version. Small version

3.2~ Tilde + specified version number (e.g. ~3.5.2)

  • Install the latest version of 3.5.x, not less than 3.5.2, but do not install 3.6.x

3.3^ Insert number + specify version number (for example ^3.5.2)

  • Install the latest version of 3.x.x, no later than 3.5.2, but do not install 4.x.x

3.4 latest

  • Install the latest version

4. File or folder function after installation

4.1 package. Json

  • Package configuration file, equivalent to Maven’s POM.xml

  • Can be used to batch download modules

    • After the node_moudles folder is removed, you can re-batch download it using “NPM install”

4.2 node_moudles folder

  • This folder is used to store the downloaded JS libraries (equivalent to maven’s local repository), which can be deleted and then re-installed using the command “NPM install”

4.3 package – lock. Json

  • Is a file generated during ” NPM install”
  • Used to record the specific source and version number of each package actually installed in the current state
  • Json is a detailed introduction to dependent modules in package.json

5. View module information

5.1 Viewing Local Installed Modules information

  • View the package in the installation directory node_modules

  • Using commands

NPM list <Module Name> # view the specified ModuleCopy the code

5.2 Viewing the Latest Remote Version of the Module

npm view <Module Name> version
Copy the code

5.3 Viewing all Remote Versions of the Module

npm view <Module Name> versions
Copy the code

6. Uninstall the module

6.1 Uninstalling a Local Module

npm uninstall <Module Name>
Copy the code

6.2 Uninstalling global Modules

npm uninstall -g <Module Name>
Copy the code

7. Enable Taobao Image acceleration

7.1 Viewing the Current Mirror Address

npm get registry
Copy the code

7.2 Configuring the Taobao Mirror Address

npm config set registry https://registory.npm.taobao.org
Copy the code
  • Command to restore the default mirror address
npm config set registry https://registry.npmjs.org/
Copy the code

7.3 Installing and downloading Modules

npm install <Module Name>
Copy the code

8.nvm

8.1 What is NVM

  • Node Version Manager,node version management tool
  • Resolve the problem that only one version of node can be installed. After installation, switch node versions
  • After the Node version is changed, the NPM is also changed

8.2 installation NVM

  • Download nVM-Windows — nVM-setup.zip
  • During the installation process, the directory Set in the Symlink step of Set Node.js is the directory that NVM use will store your nodejs program.
  • Configure the global installation path of NPM, that is, the location of the package installed using the command “NPM install -g”
    • Use the command ‘NPM config set prefix’ to configure the global installation path
    • After reconfiguring the global installation PATH, you need to modify the environment variable to change the PATH of APPDATA\Romaing\ NPM to the location of the package you set, which is used to identify commands in the globally imported package typed in the command line tool

8.3 the use of NVM

  • Download the node
NVM install latest # Download latest node version NVM install <node version number > 32 # Download the specified version, the default is 64 bits, 32 bits must be specifiedCopy the code
  • View the list of installed Nodes
nvm list
Copy the code
  • The switch node
NVM use < node version name to switch >Copy the code
  • Uninstall the node
NVM uninstall < Node version >" Uninstalls the corresponding node versionCopy the code