NPM usage and offline installation methods

Source: Internet
Author: User
Tags mysql view

The basic usage

View all the information for a module, or you can view individual information

NPM Info NAMENPM info name VERSIONNPM Info Name homepage

Install supports multiple means, package name, git path, including local path can also

sudo npm install-global [ package name]npm install git://github.com/package/path.git npm Install git:< c2>//github.com/package/path.git#0.1.0 npm Install package_name@version//local path

The premise is that the local path contains a complete package, or the file has a qualified Package.json file can be

See which packages are loaded

list NPM-globallist
Configuration file Basic Usage

Configuration is to modify the NPMRC file. This file is also modified with the command line.

NPMRC There are three locations, it is more appropriate to modify the files in the user directory.

~/.NPMRC (user home directory, win system in C:\Users\$ user name \.NPMRC)

Modifying a file is needless to say, the command configuration method

Set Key=valueset proxy=http://127.0. 0. 1:8087

Specific usage and specific key value can be viewed by opening the description document

NPM Help NPM

Configuration items can view the items that have been configured by using the following command

List List -l
Configure proxy, global directory, source

Here is a formal introduction to the domestic network approach

First, several important configuration items are introduced

Prefix-The path to the global installation, which is the location of the module where NPM install-g is installed. This is a man's hobby. I prefer to set him under the installation path.

Proxy--Agent (HTTP proxy is used this), agent connected to the network of friends this needs to be configured.

Https_proxy--HTTPS proxy

Registry-linux-like software source, this must be modified

Set "C:\nodejs" set proxy=http://127.0.0.1:8087set https_proxy=http://127.0.0.1:8087Set registry=http://registry.npmjs.org

Registry=http://registry.npmjs.org This sentence is very important, note that the default source is https://registry.npmjs.org is HTTPS, anyway I even the default source is never successful once.
The above example I fixed him as unencrypted http is basically normal.

Network can not consider some of the domestic source test, such as

Set "http://r.cnpmjs.org/"
Offline installation

There are many environments where a proxy is configured, the source is modified, or a network problem occurs. A common hint is shasum check failed. Of course, this is not necessarily the network does not work, but most of the situation is the network connection is not smooth caused.

In this case can be manually downloaded and installed, in fact, it is very simple.

First find ways to download the package you need, this can be a variety of ways. or copy it from another machine.

For example, the NPM info mysql view MySQL This package information, package information will have the software homepage or code warehouse address. Half on GitHub. (Install because the download may fail, but the info command information is usually successful).

For example, the address of Node-mysql in Https://github.com/felixge/node-mysql

After the download to extract to the project Node_modules directory is installed, it is so simple.

Project

---Package.json

---index.js

---node_modules//Unzip to this directory (package.json,index.js file below each package folder). )

Note: The source package you downloaded may not be the same as the module name. To rename the module name and then copy into the Node_modules. For example, rename the Node-mysql folder to MySQL.

Dependencies between packages offline installation issues

The above method installs the package does not contain the dependent package, but the dependency package also uses above offline installs the method also to be possible.

For example, the MySQL package relies on bignumber.js, Readable-stream, Require-all three packages. NPM installs dependencies by default in a layer down. For example, installing the MySQL engineering structure would be like this

Project

---Package.json

---index.js

---node_modules

---MySQL

---node_modules

---bignumber.js

---readable-stream

---require-all

You also only need the same action to put the dependent package in the appropriate location. This structure of package management is complex but the dependencies are clear. But this is not necessarily the case, you can also put the dependency package in the first layer of the Node_modules folder. The Nodejs search module path is searched one layer at a level.

NPM usage and offline installation methods

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.