npm source management

Reference: http://www.tuicool.com/articles/nYjqeu

Reference: http://www.jianshu.com/p/0deb70e6f395

Reference: http://yijiebuyi.com/blog/b12eac891cdc5f0dff127ae18dc386d4.html


Overview

npm is the official package management tool of nodejs, on which you can download various third-party packages, which are often used in projects. However, the official download source is outside the wall, the download speed is very slow, and it often times out and fails. So we need to replace a faster download source, generally choose Taobao source in China.


Modify the source

 Modify the source (temporary)

npm --registry https://registry.npm.taobao.org install express


set source (long term)

npm config set registry https://registry.npm.taobao.org

Note: It is said that this method will fail after restarting the computer. I have not tried it.


Modify configuration files (long term)

vim ~/.npmrc //Open the configuration file
registry =https://registry.npm.taobao.org //Write the configuration file

cnpm

cnpm is an npm mirroring tool from Taobao that supports publishing LAN modules. The usage method is the same as npm, except that the command becomes cnpm. Official website: https://npm.taobao.org/

npm install -g cnpm --registry=https://registry.npm.taobao.org


NRM

Overview

nrm is an npm source management tool that can switch sources freely

Install

npm install -g nrm

It is recommended to install nrm after replacing the source as above, otherwise it will take a long time, or
npm install -g nrm --registry https://registry.npm.taobao.org

Order

nrm ls: View all sources, the one marked with [*] is the currently selected source, and the format is registry --- url
nrm use <registry>: switch to the source of the corresponding name
nrm add <registry> <url> [home]: Add source. The name can be customized. home is generally used for npm package management in the local area network
nrm del <registry>: delete source
nrm test [registry]: Test source response time, if no source name is added, test the response time of all sources


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325687245&siteId=291194637