Home > Web Front-end > JS Tutorial > How to quickly switch NPM sources

How to quickly switch NPM sources

一个新手
Release: 2017-10-11 09:59:53
Original
1530 people have browsed it

We have introduced cnpmjs.org and the recently launched Taobao before npm Two NPM images. In addition, there are some foreign NPM images. The speed of accessing different mirrors in different regions may be different, and each mirror may have a small number of packages that are temporarily out of sync. Therefore, sometimes it is necessary to switch NPM mirrors. Compared with manually specifying the corresponding parameters every time you switch, using nrm is much more convenient.

nrm is an NPM source manager that allows you to quickly switch between the following NPM sources:

  • npm

  • cnpm

  • strongloop

  • european

  • australia

  • nodejitsu

  • taobao

Installation

; npm install -g nrm
Copy after login

Use

List optional sources

; nrm ls                                                                                                                                    * npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - http://registry.npm.taobao.org/
  eu ----- http://registry.npmjs.eu/
  au ----- http://registry.npmjs.org.au/
  sl ----- http://npm.strongloop.com/
  nj ----- https://registry.nodejitsu.com/
Copy after login

The one with * is the source currently used. The above output indicates that the current source is the official source.

Switch

Switch to taobao

; nrm use taobao                                                                                                                             

   Registry has been set to: http://registry.npm.taobao.org/
Copy after login

Add source

You can add customized sources, especially suitable for adding private sources within the enterprise. Private sources can be built using cnpmjs.

nrm add  <registry> <url> [home]
Copy after login

Delete source

nrm del <registry>
Copy after login

Test speed

You can also test the response time of the corresponding source through nrm test.

For example, test the response time of the official source:

; nrm test npm                                                                                                                               

  npm ---- 1328ms
Copy after login

Test the response time of all sources:

; nrm test                                                                                                                                   

  npm ---- 891ms
  cnpm --- 1213ms* taobao - 460ms
  eu ----- 3859ms
  au ----- 1073ms
  sl ----- 4150ms
  nj ----- 8008ms
Copy after login

Note that in order to obtain more accurate results, you can consider multiple tests take the average.

License

nrm is open source software licensed under the MIT license.

The above is the detailed content of How to quickly switch NPM sources. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template