Packages and NPM (NPM common instructions)

package structure

A package conforming to the CommonJS specification, the directory structure should be:

  • package.json: The description file of the package
  • bin: directory for storing executable binaries
  • lib: directory for storing Javascript code
  • doc: directory for storing documents
  • test: code used to store unit test cases

Description file package.json

ConmmonJS defines some mandatory fields for package.json:

field name describe
name Package names
desciption Package Profile
version version number
keywords keyword array, used for classification search of NPM
maintainers List of package maintainers
contributors list of contributors
bugs Web address for reporting bugs
licenses List of licenses used by the current package
repositories List of locations where source code is hosted
dependencies list of packages required to use the current package

NPM common functions

npm -v

Used to view the current npm version

npm install

You can use the npm i shorthand. Mainly used to install dependent packages.

npm init

Initialize an npm package. After executing this command, a package.json will be generated in the package.

npm adduser

Create an account in the NPM repository

npm publish

Upload package to NPM repository

npm owner

Manage package permissions. Normally, only one person has permission to publish a package. Use this command to add permissions to others

npm ls

Analyze packages, you can analyze all packages that can be found through the module path under the current path, and generate the number of dependencies.
For example, to check what other dependent packages a package introduces, you can use this function

Guess you like

Origin blog.csdn.net/weixin_46726346/article/details/131802215