npm镜像源管理

1、查看npm源地址
命令:

npm config list

 返回:

; cli configs
user-agent = "npm/3.10.10 node/v6.17.1 linux x64"

; node bin location = /usr/bin/node
; cwd = /home/www
; HOME = /home/www
; "npm config ls -l" to show all defaults.

命令: 

npm config ls -l

返回: 

...
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
...

2、修改registry地址,比如修改为淘宝镜像源。

命令:

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

查询配置:

...
; userconfig /home/www/.npmrc
registry = "https://registry.npm.taobao.org/"
...
...
rebuild-bundle = true
; registry = "https://registry.npmjs.org/" (overridden)
rollback = true
...

如果有一天你肉身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

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 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值