JavaScript full analysis - npm

Introduction to npm

●Know npm
○A package manager based on node environment

● Installation of npm
○ No installation is required, as long as node is installed, npm will be installed automatically

●npm detection
○Open the command line, the directory does not matter
○Enter the command: npm --version || npm -v

●The role of npm
○Download all third parties related to js
○Equivalent to a "software"
○It's just that this "software" has no icon, no UI interface
○Rely on the command line to operate
the basic use of npm

●npm initialization
●Switch to the root directory of the project, open cmd and enter npm init
●package name: project name; the default file directory name does not support Chinese and spaces
●version: initial version of the project; default 1.0.0 usually the first version is 0.0.1 Or 0.1.0
●description: project description, which belongs to a paragraph describing your project content is enough
●entry point: project entry, the default is index.js generally needed for the backend
●keywords: keywords
●author: author
●Switch to Project root directory, open cmd and enter npm init --yes || npm init -y
All options are configured according to default values

Common commands for npm

1.npm download third party

1.1. Switch to the project root directory, enter the command npm install package name
1.2. Switch to the project root directory, enter the command npm i package name
1.3. After downloading and installing, there will be one more package-lock.json file and node_modules folder by default
1.4. Download , it will download the specified third-party package. If the third-party package uses other third-party packages, it will be downloaded to node_modules together.
1.5. After the download is complete, it will be automatically recorded in package.json

2.npm View third-party downloadable versions

2.1. Open cmd, the directory does not matter
2.2. Enter the command: npm view package name versions
2.3. All downloadable versions of the third-party package will be displayed

3.npm download the specified version of the third party

3.1. Open cmd, switch to the root directory of the project, and enter the command npm install package name@version number|| npm i package name@version number
3.2. Note: During installation, only one will be recorded in the package, and subsequent installations will replace it The previously installed
3.3. version number can write the full version number, or write the major version number, and the latest stable version in the major version will be downloaded by default

4.npm delete third party

4.1. Open cmd, switch to the project root directory
4.2. Enter the command npm install package name || npm un package name
4.3. The local file of the third-party package will be deleted, and the records in the package.json file will be deleted

5.npm downloads all third parties in a unified way

5.1. Open cmd, switch to the project root directory
5.2. Enter the command npm install || npm i
5.3. Note! The project root directory needs to have package.json
5.4. It will automatically read the third-party packages recorded in package.json, one-time Download and install all

6. npm clear cache

6.1. Clear the download cache
6.1.1. Open cmd, the directory does not matter
6.1.2. Enter the command: npm cache clear -f

6.2. Clear local cache
6.2.1. C disk
6.2.2. User
6.2.3. Your username
6.2.4.AppData
6.2.5.Roaming
6.2.6.npm-cache

7. Modify the mirror source address

7.1. Modify the download address of the npm third-party package
7.2. Open the command line, the directory does not matter
7.3. Enter the command: npm config set registry https://registry.npmmirror.com

おすすめ

転載: blog.csdn.net/sdasadasds/article/details/131168300