# 使用 nrm 管理前端項目 nodejs 模塊 npm 安裝源(registry)地址
nrm 即是因此類需求而產生的,它是一個用于快速切換 npm 源地址的 nodejs 工具。
## 1\. 使用 nrm
安裝 nrm:
~~~
npm i -g nrm
~~~
nrm 通過別名簡寫的方式讓你能夠快速切換 registry。它默認設置了一些常用源的簡寫。
~~~
nrm ls
~~~
得到默認定義的源列表:
~~~
npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
rednpm - http://registry.mirror.cqupt.edu.cn/
npmMirror - https://skimdb.npmjs.com/registry/
edunpm - http://registry.enpmjs.org/
~~~
我們可以添加內部私有的源到列表,以便于后續快速切換。示例:
~~~
nrm add lzwme https://registry.lzw.me https://npm.lzw.me
nrm add yarn https://registry.yarnpkg.com https://yarnpkg.com/zh-Hans/
nrm use lzwme
~~~
更多 nrm 命令參考:
~~~
ls List all the registries
current Show current registry name
use <registry> Change registry to registry
add <registry> <url> [home] Add one custom registry
del <registry> Delete one custom registry
home <registry> [browser] Open the homepage of registry with optional browser
test [registry] Show response time for specific or all registries
help Print this help
~~~
如欲知更為詳細的細節,可前往 nrm 項目地址了解:
nrm: https://github.com/Pana/nrm
## 2\. 使用淘寶鏡像地址
一些模塊在安裝過程中還需要實時下載二進制的資源,這個地址是模塊內默認定義的,可不在 registry 可控的范圍內。不過一般他們都會提供環境變量配置指定安裝來源,而淘寶倉庫提供了一些流行模塊的鏡像源,這使得我們可以較為順利地安裝上這些模塊。
使用淘寶鏡像源地址參考:
~~~
npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/
~~~
更多列表可前往淘寶 npm 頁面參考:https://npm.taobao.org
## 3\. 相關 URL 參考
* npmconfig[https://docs.npmjs.com/misc/config](https://docs.npmjs.com/misc/config)
* nrm[https://github.com/Pana/nrm](https://github.com/Pana/nrm)
* npm[https://www.npmjs.org](https://www.npmjs.org/)
* cnpm[http://cnpmjs.org](http://cnpmjs.org/)
* taobao[https://npm.taobao.org](https://npm.taobao.org/)
* nvm[https://github.com/creationix/nvm](https://github.com/creationix/nvm)