NodeJS basic knowledge 2

Package

  • The CommonJS package specification allows us to group related modules together to form a complete set of tools.
  • The CommonJS package specification consists of two parts: the package structure and the package description file.
  • Package structure: used to organize various files in the package
  • Package description file: describes the relevant information of the package for external reading and analysis

Package structure

Insert picture description here
Note: Except package and json files are required, other files are not required.

Package description file

Insert picture description here

NPM(Node Package Manager)

For Node, NPM helped it complete the release, installation and dependency of third-party modules. With the help of NPM, a good ecosystem has been formed between Node and third-party modules.

npm command

command Paraphrase
npm -v Check the version of npm
npm version View the version of all modules
above sea level View help description
npm search package name Search module package
npm -v Check the version of npm
npm install / i package name Install the package in the current directory
npm install / i package name -g Global installation packages (global installation packages are generally some tools, such as: cnpm)
npm remove / r package name Delete package
npm install / i package name Install the package in the current directory
npm install / i 包名 --save Install the package and add it to the dependencies (that is, the dependencies in the package description file are based on the corresponding package name)
npm install / i package name-registry=URL Install the package from the mirror source
npm config set registry URL Set the mirror source

Insert picture description here

supplement

We can add a "package.json" file under a folder, and then enter the command npm i, node will automatically help us download the dependent packages in the package.json file, and after the command is executed, a node_modules will be added under the folder Folder and package-lock.json file (description information for the downloaded package file). The package.json file is shown in the figure below.
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_36828822/article/details/105881374