npm配置镜像、设置代理

时间:2025-01-25 13:06:56

配置镜像

  • by config command

    npm config set registry 
    npm info underscore (如果上面配置正确这个命令会有字符串response)

  • 命令行指定

    npm --registry  info underscore

  • 编辑 ~/.npmrc 加入下面内容

    registry = 

设置代理

npm config set proxy http://server:port
npm config set https-proxy http://server:port

如果需要认证的话可以这样设置:

npm config set proxy http://username:password@server:port
npm confit set https-proxy http://username:password@server:port

如果代理不支持https的话需要修改npm存放package的网站地址。

npm config set registry "/"

使用nrm快速切换npm源

nrm 是一个 NPM 源管理器,允许你快速地在如下 NPM 源间切换:

  • 列表项目
  • npm
  • cnpm
  • strongloop
  • enropean
  • australia
  • nodejitsu
  • taobao

Install

sudo npm install -g nrm

如何使用?

列出可用的源:

  ➜  ~  nrm ls
  npm ---- https:///
  cnpm --- http:///
  taobao - http:///
  eu ----- http:///
  au ----- http:///
  sl ----- http:///
  nj ----- https:///
  pt ----- http:///

切换:

➜  ~  nrm use taobao
   Registry has been set to: /

增加源:

nrm add <registry> <url> [home]

删除源:

nrm del <registry>

测试速度:

nrm test