The road of my Node.js Learning (ii) NPM module management _node.js

Source: Internet
Author: User
Tags require install node

NPM is a node package management and distribution tool that has become the unofficial standard for publishing node modules (packages). With NPM, you can quickly find the packages that a particular service will use, download, install, and manage the packages that are already installed.

NPM's Common commands are:

(1) $ npm Install Modulenames
Install node module
Note: If you do not know its name when using the module, you can use the Http://search.npmjs.org website to follow
Index value to find the module you want. NPM also provides the function of the query $ NPM Search IndexName
After installation, a node_modules directory is created, with each node module installed in its directory.
Node installation is divided into global mode and local mode. Normally run in local mode, package will be installed
To the local node_modules directory with your application code statistics. In global mode, the node package is
Install to the Node_modules under the node's installation directory. The Global installation command is
$ NPM install-g modulename. Learn to set installation mode using $NPM set Global=true
, $NPM get global can view the installation mode that is currently in use.

      (2) $ npm view Modulenames
                  View the node module's Package.json folder
                 Note: If you want to see the contents of a label under the Package.json folder, you can use the
                                   $ npm View ModuleName labelname

(3) $ NPM list
View installed node packages in the current directory
Note: The node module search starts at the current directory where the code executes, and the search results depend on the current directory in use
Under the node_modules of the content. $ NPM List parseable=true can be in the form of catalogs to show when
All node packages that were previously installed

(4) $ NPM Help
View Help Commands

(5) $ npm View moudlename dependencies
To view the dependencies of a package

(6) $ npm View ModuleName Repository.url
To view the source file address of a package

(7) $ NPM View ModuleName engines
View the version of node on which the package depends

(8) $NPM Help folders
View all folders used by NPM

(9) $ NPM Rebuild ModuleName
To rebuild after the package content is changed

(a) $ npm outdated
Check that the package is obsolete, this command lists all outdated packages and can be updated in a timely manner

(one) $ NPM update modulename
Update Node Module

(a) $ npm uninstall Moudlename
Uninstall Node module

(13) A NPM package is a folder that contains Package.json, Package.json describes the structure of the folder. Visit
The way to ask NPM's JSON folder is as follows:
$ NPM Help JSON
This command opens a Web page by default and may not be typed as a Web page if the default open program is changed
Open.

(14) When you publish a NPM package, you need to verify that a package name exists
$ NPM Search PackageName

(15) Many times when we use a NPM package, we often forget to require its interdependent modules, and we can
See what packages are dependent on this module by using the following command

NPM is the Node.js Package Manager. It is often used to install/uninstall packages when developing Node.js. In fact, the job of publishing a package is also done by it.

Configure Package.json

To package the program, you first need to match the settings, which are specified by the Package.json in the program package root directory. The content of the Package.json must be in a strict JSON format, which means:

Strings should be enclosed in double quotes, but not in single quotes;
Attribute names must be double quotes;
Never add a comma after the last attribute.
Configuration objects have a lot of properties, you can see here, here is a list of commonly used items:

Name: The package name cannot be duplicated with an existing package.
Version: Edition number.
Description: A brief introduction.
Author: author information. Contains the name, email, url three property.
Bin: If there is an executable file in the program (mainly called in the command line), specify it here, and you can specify more than one.
Main: The program entry when using require to invoke this package.
Dependencies: Dependent packages, you can specify a version number.

After the Package.json is configured, you can pack and install it locally once, and the test program works properly, and the installation commands are:

NPM Install < local path >

In addition, there is a hidden rule to note that if you want the executable program in the package to run in a node.js environment, then add one line to the front of the program entry file:

#!/usr/bin/env node

Without this line, it will open in the default mode of the system instead of running in a node.js environment.

Register 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 is also done through the command line:

NPM AddUser
After you execute this command, you will be prompted to enter your username, Email, password, and then wait a little while.

Publishing Packages

The preparation is done, and you can publish the package by executing the following command:

NPM Publish < Local path >
If you want to update the package, just change the version number in Package.json, and then execute the release command again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.