前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Node.js】:配置源(registry)、代理(proxy)

【Node.js】:配置源(registry)、代理(proxy)

作者头像
WEBJ2EE
发布2021-01-28 15:47:31
10.3K0
发布2021-01-28 15:47:31
举报
文章被收录于专栏:WebJ2EE
代码语言:javascript
复制
目录
1. 背景
2. npm
  2.1. 配置镜像源
  2.2. 配置代理
3. yarn
  3.1. 配置镜像源
  3.2. 配置代理

1. 背景

换npm、yarn的镜像源,或配置npm、yarn的代理,都是为了解决 npm 依赖下载慢的问题。

  • 如果你要下载的依赖,都能在“淘宝”或者“cnpm”镜像源上找到,那么换镜像源就能加速很多。
  • 如果你必须通过“npm镜像源”下载依赖(例如:你依赖的某特定版本的库,淘宝、cnpm镜像源上还没来得及与 npm 镜像源同步),那么你就需要配置代理科学上网(如果你有VPN,那更省事)。

2. npm

2.1. 配置镜像源

  • 方式1:npm 命令
代码语言:javascript
复制
// 查看镜像源
npm config get registry

// 设置镜像源
npm config set registry http://registry.npm.taobao.org/
npm config set registry https://registry.npmjs.org/
  • 方式2:nrm 工具
    • nrm can help you easy and fast switch between different npm registries, now include: npm, cnpm, taobao, nj(nodejitsu).
代码语言:javascript
复制
npm install -g nrm // 安装
nrm ls // 查看已有的源
nrm use <registry> // 切换源
nrm add <registry> <url> // 添加源
nrm del <registry> // 删除源
nrm test [registry] // 测速

2.2. 配置代理

代码语言:javascript
复制
// 查看代理
npm config get proxy
npm config get https-proxy

// 设置代理
npm config set proxy http://127.0.0.1:8080
npm config set https-proxy http://127.0.0.1:8080

// 删除代理
npm config delete proxy
npm config delete https-proxy

3. yarn

3.1. 配置镜像源

代码语言:javascript
复制
// 查看镜像源
yarn config get registry

// 设置镜像源
yarn config set registry http://registry.npm.taobao.org/
yarn config set registry https://registry.npmjs.org/

3.2. 配置代理

代码语言:javascript
复制
// 查看代理
yarn config get proxy
yarn config get https-proxy

// 设置代理
yarn config set proxy http://127.0.0.1:8080
yarn config set https-proxy http://127.0.0.1:8080

// 删除代理
yarn config delete proxy
yarn config delete https-proxy

参考:

NPM registry manager(nrm): https://github.com/Pana/nrm npm Docs: https://docs.npmjs.com/cli/v6/using-npm/config#proxy https://docs.npmjs.com/cli/v6/using-npm/config#https-proxy

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-01-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 WebJ2EE 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
VPN 连接
VPN 连接(VPN Connections)是一种基于网络隧道技术,实现本地数据中心与腾讯云上资源连通的传输服务,它能帮您在 Internet 上快速构建一条安全、可靠的加密通道。VPN 连接具有配置简单,云端配置实时生效、可靠性高等特点,其网关可用性达到 99.95%,保证稳定、持续的业务连接,帮您轻松实现异地容灾、混合云部署等复杂业务场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档