1. Introduction of NPM

NPM is an official package management tool provided by Node.js. Developers can use NPM to upload shared code, install and manage project dependencies.

2. Installation and version

Nodejs is already integrated with NPM, and if native NodeJS is installed, NPM is installed as well

 node -v // Check the nodejs version
Copy the code
 npm -v // Check the NPM version
Copy the code

If nodeJS is not installed, download the official nodeJS installation package and install it at nodejs.org/en/download…

3. The source management

3.1 Viewing the NPM Source

npm config get registry
Copy the code

3.2 Setting taobao NPM image

npm config set registry https://registry.npmjs.org
Copy the code

If you do not want to set the NPM image to Taobao, you can use CNPM. CNPM can be used instead of NPM

3.3 Installing CNPM

npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy the code

3.4 NPM upgrade

NPM upgrade to a version

npm install npm@7.8. 0 -g 
Copy the code

NPM updated to the latest

npm install npm@latest -g 
Copy the code

4. Install the dependency packages

The loadash library is used as an example

4.1 Local Project Installation

npm install loadash / / the whole writing
npm i loadash / / abbreviation
Copy the code

Loadash is installed in the project node_modules directory

4.2 Global Installation

npm install -g loadash
Copy the code

Loadash is installed globally and will not be installed in the project node_modules directory

4.3 Installing to devDependencies

npm install --save-dev loadash / / the whole writing
npm install --D loadash / / abbreviation
Copy the code

Loadash depends on the devDependencies node written to the package.json file

4.4 Installing to Dependencies

npm install --save loadash / / the whole writing
npm install --S loadash / / abbreviation
Copy the code

The loadash dependency is written to the Dependencies node of the package.json file

5. Update the dependency package

npm update  loadash
Copy the code

6. Uninstall the dependency packages

npm uninstall  loadash
Copy the code