原始源
安装完node之后,默认的原始源是:
https://registry.npmjs.org/
原始源在国外,所以速度受到限制。
可以通过安装cnpm使用淘宝镜像来进行加速:
// 安装cnpm命令,不会改变npm的源
npm install -g cnpm --registry=https://registry.npm.taobao.org
//使用
cnpm install
但是使用cnpm有时会有一些奇怪的错误,可以通过改变源的方式来进行加速。
使用 npm
命令的时候,可以指定源:
//本次从淘宝仓库源下载
npm --registry=https://registry.npm.taobao.org install
可以直接设置源,源可以是多个,但只有一个是生效的。
//设置淘宝源
npm config set registry https://registry.npm.taobao.org
//设置公司的源
npm config set registry http://127.0.0.1:4873
//查看源,可以看到设置过的所有的源
npm config get registry
也可以修改 ~/.npmrc
,添加源的设置:
registry = https://registry.npm.taobao.org
nrm
是一个 NPM 源管理器,可以使用 nrm
在不同的源切换。
npm install -g nrm
nrm ls
结果:
* npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
带*
的是当前使用的源。
切换到taobao:
nrm use taobao
可以增加定制的源,特别适用于添加企业内部的私有源。
nrm add <registry> <url> [home]
nrm del <registry>
还可以通过 nrm test
测试相应源的响应时间。
nrm test npm
结果:
npm ---- 1328ms
参考:
【1】:npm设置和查看仓库源
【2】:设置npm源的几种方式
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有