关于node.js:npm更换国内源解决npm-install慢的问题

3次阅读

共计 1167 个字符,预计需要花费 3 分钟才能阅读完成。

1. 问题还原

在国内应用 npm 装置的时候,会十分迟缓,

npm install 

倡议应用淘宝的镜像仓库来代替的原有的镜像仓库(镜像仓库就是一个 npm 的下载源,换成国内的下载源,下载速度会晋升很多)

2. 解决方案

侥幸的是, 国内有几个镜像站点能够供咱们应用,速度十分快, 镜像站会实时更新, 为咱们节俭了好多工夫. 如何给本机换源呢?

(1)[长期] 通过 config 配置指向国内镜像源

# 配置指向源
$ npm config set registry http://registry.npm.taobao.org

(2)[长期] 通过 npm 命令指定下载源

# 在装置时候长期指定
$ npm --registry http://registry.cnpmjs.org info express

(3)长久应用

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

(4)永恒批改镜像源

查看 npm 配置

$ npm config list
# 其余查看配置的形式
$ npm config get globalconfig
$ npm config ls -l

找到并关上配置文件:~/.npmrc
写入配置:registry=https://registry.npm.taobao.org

3. 验证设置是否胜利

npm config get registry
# OR
npm info express

4. 重要揭示

不举荐通过 cnpm 应用,会呈现各种莫名的问题。

5. 其余镜像

  • 开源镜像: http://npm.taobao.org/mirrors
  • Node.js 镜像: http://npm.taobao.org/mirrors/node
  • alinode 镜像: http://npm.taobao.org/mirrors/alinode
  • phantomjs 镜像: http://npm.taobao.org/mirrors/phantomjs
  • ChromeDriver 镜像: http://npm.taobao.org/mirrors/chromedriver
  • OperaDriver 镜像: http://npm.taobao.org/mirrors/operadriver
  • Selenium 镜像: http://npm.taobao.org/mirrors/selenium
  • Node.js 文档镜像: http://npm.taobao.org/mirrors/node/latest/docs/api/index.html
  • NPM 镜像: https://npm.taobao.org/mirrors/npm/
  • electron 镜像: https://npm.taobao.org/mirrors/electron/
  • node-inspector 镜像: https://npm.taobao.org/mirrors/node-inspector/
正文完
 0