Home > Article > Web Front-end > My Node.js learning journey NPM module management
NPM is a Node package management and distribution tool that has become an unofficial standard for publishing Node modules (packages). With NPM, you can quickly find the packages used by specific services, download, install and manage installed packages.
Commonly used commands for NPM are:
’ s ’ s ’ through ‐ ‐ ‐ ‐ ‐ Str inInstallInstallation 的 The index value finds the module you want. npm also provides the query function $ npm search indexName
The installation of node is divided into global mode and local mode. Under normal circumstances, it will be run in local mode, and the package will be installed into the local node_modules directory that contains your application code statistics. In global mode, the Node package will be installed into node_modules in the Node installation directory. The global installation command is
Learned to use $npm set global=true to set the installation mode
(2) $ npm view moduleNames
View the package.json folder of the node module
Notes: If you want to view the content of a tag under the package.json folder, you can use $ npm view moduleName labelName
(3) $ npm list The content under node_modules. $ npm list parseable=true can display all node packages currently installed in the form of a directory
(4) $ npm help
(5)$ npm view moudleName dependencies
(6) $ npm view moduleName repository.url
View the source file address of the package
View the version of Node that the package depends on
Check whether the package is out of date, This command will list all outdated packages, which can be updated in time
Update Node module
(12) $ NPM Uninstall MoudLename
Uninstall Node module (13 ) An npm package is a folder that contains package.json, which describes the structure of this folder. The method to access the npm json folder is as follows:
The web page form opens.
(14) When publishing an npm package, you need to check whether a package name already exists
For dependent modules, we can use the following command to check the interdependent packages of this module. npm is the package manager of Node.JS. When doing Node.JS development, it is often used to install/uninstall packages. In fact, it does the work of publishing packages.
Configure package.json
To package a program, you must first configure various settings. These settings are specified by package.json in the root directory of the package. The content of package.json must be in strict JSON format, that is to say:
The string must be enclosed in double quotes, not single quotes;
The attribute name must be enclosed in double quotes;
Never after the last attribute Add an extra comma.
There are many attributes of the configuration object. For details, please refer to here. Here are the commonly used items:
name: package name, which cannot be repeated with an existing package.
description: a short introduction.
author: author information. Contains three attributes: name, email, and url.
bin: If there is an executable file in the program (mainly called from the command line), specify it here. You can specify multiple ones.
dependencies: Dependent packages, you can specify the version number.
After configuring package.json, you can package and install it locally first to test whether the program operates normally. The installation command is:
npm install
#!/usr/bin/env node
Register an npm account
To publish the package to npm, you need to register an account first. npm does not provide a web version of the registration wizard. Registration also needs to be done through the command line:
npm adduser
After executing this command, you will be prompted to enter your username, email, and password. After entering it, just wait for a while.
npm publish