此文列出常見npm命令,大家共勉。
1、查看npm源地址
npm config list
結果:
metrics-registry = "http://registry.npm.taobao.org/"
2、修改registry地址,比如修改為淘寶鏡像源。
npm set registry https://registry.npm.taobao.org/
如果有一天你肉身FQ到國外,用不上了,用rm命令刪掉它
npm config rm registry
3、nrm是專門用來管理和快速切換私人配置的registry
建議全局安裝
npm install nrm -g --save
用nrm ls命令查看默認配置,帶*號即為當前使用的配置
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 current
切換源
nrm use cnpm
用nrm add 命令添加公司私有npm源,如http://registry.npm.360.org(隨便寫的),起個別名叫qihoo
nrm add qihoo http://registry.npm.360.org
測試下速度
nrm test npm
輸出npm ---- 790ms
最后,如果你被公司開除了,怒刪公司npm源配置
nrm del qihoo
4、更新Node
版本和npm
版本
清除node的cache(清除node的緩存,這個看情況而定,不是必須的)
sudo npm cache clean -f
安裝"n"版本管理工具,管理node(沒有錯,就是n)
sudo npm install -g n
更新node版本
sudo npm install npm@latest -g
再查一遍本機當前Node和npm的版本吧
node -v
npm -v