专业的编程技术博客社区

网站首页 > 博客文章 正文

nodejs|npm加速安装node_module模块

baijin 2024-08-22 09:18:00 博客文章 5 ℃ 0 评论

nodejs|npm加速安装node_module模块

前言

npm默认源为https://registry.npmjs.org/,但是下载速度慢。下面介绍一下如何加速下载模块。

1.临时设置

npm i express --registry https://registry.npm.taobao.org

2.永久设置

2.1 npm config命令

设置:

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

查看:

npm config get registry

2.2 npmrc文件

编辑 ~/.npmrc 加入下面内容(上面的命令也是设置该文件)

registry = https://registry.npm.taobao.org

2.3 nrm命令管理源

npm i nrm -g --registry https://registry.npm.taobao.org

查看源

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/

测试源速度

nrm test 

* npm ---- 1069ms
  yarn --- 2328ms
  cnpm --- 689ms
  taobao - 103ms
  nj ----- Fetch Error
  npmMirror  935ms
  edunpm - Fetch Error

切换源

nrm use taobao

nrm帮助

nrm --help

Usage: cli [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

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表