node : npm / nrm(npm registry manager ) : 切换源
Posted Mars-xq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node : npm / nrm(npm registry manager ) : 切换源相关的知识,希望对你有一定的参考价值。
一、npm传统设置
设置:
以前都是这样切换taobao源:
# 淘宝
npm config set registry https://registry.npm.taobao.org --global
yarn config set registry http://registry.npm.taobao.org/ --global
# 官网
npm config set registry https://registry.npmjs.org/ --global
查看
> npm config get registry
https://registry.npm.taobao.org/
或
> npm config list
; cli configs
metrics-registry = "https://registry.npm.taobao.org/"
scope = ""
user-agent = "yarn/1.15.2 npm/? node/v14.2.0 darwin x64"
; environment configs
bin-links = true
disturl = "https://npm.taobao.org/dist"
init-license = "MIT"
init-version = "1.0.0"
registry = "https://registry.npm.taobao.org/"
save-prefix = "^"
strict-ssl = true
user-agent = "yarn/1.15.2 npm/? node/v14.2.0 darwin x64"
version-commit-hooks = true
version-git-message = "v%s"
version-git-tag = true
version-tag-prefix = "v"
; userconfig /Users/tmk/.npmrc
home = "https://www.npmjs.org"
; globalconfig /Users/tmk/.nvm/versions/node/v14.2.0/etc/npmrc
; node bin location = /Users/tmk/.nvm/versions/node/v14.2.0/bin/node
; cwd = /Users/tmk
; HOME = /Users/tmk
; "npm config ls -l" to show all defaults.
或
> npm info express
express@4.17.1 | MIT | deps: 30 | versions: 264
Fast, unopinionated, minimalist web framework
http://expressjs.com/
dist
.tarball: https://registry.npm.taobao.org/express/download/express-4.17.1.tgz
.shasum: 4491fc38605cf51f8629d39c2b5d026f98a4c134
dependencies:
accepts: ~1.3.7 cookie-signature: 1.0.6 escape-html: ~1.0.3 methods: ~1.1.2 qs: 6.7.0
array-flatten: 1.1.1 cookie: 0.4.0 etag: ~1.8.1 on-finished: ~2.3.0 range-parser: ~1.2.1
body-parser: 1.19.0 debug: 2.6.9 finalhandler: ~1.1.2 parseurl: ~1.3.3 safe-buffer: 5.1.2
content-disposition: 0.5.3 depd: ~1.1.2 fresh: 0.5.2 path-to-regexp: 0.1.7 send: 0.17.1
content-type: ~1.0.4 encodeurl: ~1.0.2 merge-descriptors: 1.0.1 proxy-addr: ~2.0.5
(...and 6 more.)
maintainers:
- dougwilson <doug@somethingdoug.com>
- jasnell <jasnell@gmail.com>
- mikeal <mikeal.rogers@gmail.com>
dist-tags:
latest: 4.17.1 next: 5.0.0-alpha.8
published over a year ago by dougwilson <doug@somethingdoug.com>
二、nrm设置(推荐)
nrm
(npm registry manager
)是npm的镜像源管理工具
,有时候国外资源太慢,
使用这个就可以快速地在 npm 源间切换
安装 nrm
npm install -g nrm
查看帮助
> nrm -h
Usage: nrm [options] [command]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
ls List all the registries
current Show current registry name
use <registry> Change registry to registry
add <registry> <url> [home] Add one custom registry
set-auth [options] <registry> [value] Set authorize information for a custom registry with a base64 encoded string or username and pasword
set-email <registry> <value> Set email for a custom registry
set-hosted-repo <registry> <value> Set hosted npm repository for a custom registry to publish packages
del <registry> Delete one custom registry
home <registry> [browser] Open the homepage of registry with optional browser
publish [options] [<tarball>|<folder>] Publish package to current registry if current registry is a custom registry.
if you're not using custom registry, this command will run npm publish directly
test [registry] Show response time for specific or all registries
help Print this help
查看镜像源列表
> 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 current
taobao
或
> npm config get registry
https://registry.npm.taobao.org/
切换到淘宝镜像源
> nrm use taobao
测试相应源的响应时间
> nrm test npm
> nrm test taobao
以上是关于node : npm / nrm(npm registry manager ) : 切换源的主要内容,如果未能解决你的问题,请参考以下文章