Verdaccio介绍及安装 -- nodejs私有npm proxy registry代理

Verdaccio 是一个 Node.js创建的轻量的私有npm proxy registry
Verdaccio 是一个跨平台的 Web 应用程序。 在安装之前,您需要确保系统环境已满足以下条件。

Prerequisites

  1. Node.js v12 or higher.
  2. npm >=4.xyarn > 我们强烈建议使用最新的 Node 包管理客户端 > npm@5.x | yarn@1.x | pnpm@2.x

我们强烈建议使用最新版本的Node包管理工具,比如> npm@6.x | yarn@1.x | | yarn@2.x | pnpm@6.x。 不再支持npm@5.x或更低版本。

  1. 使用现代浏览器以访问Web界面, 支持使用 Chrome、 Firefox、 Edge和IE11 浏览器。

Verdaccio 将根据 Node. js 发布工作组 的推荐支持最新的 Node. js 版本。

仍在使用 Verdaccio 4? 查看 迁移指南

快速开始

在开始之前学习基础:如何安装、配置文件的位置在哪里等等。

安装CLI

在生产环境中使用Verdaccio前,请先阅读并了解 最佳实践案例

Verdaccio must be installed globally using either of the following methods:

Using npm

npm install -g verdaccio

or using yarn

yarn global add verdaccio

or using pnpm

$> verdaccio
warn --- config file  - /home/.config/verdaccio/config.yaml
warn --- http address - http://localhost:4873/ - verdaccio/3.0.0

install verdaccio

Docker 镜像

Once it has been installed, you only need to execute the CLI command:

$> verdaccio
warn --- config file  - /home/.config/verdaccio/config.yaml
warn --- http address - http://localhost:4873/ - verdaccio/5.0.0

For more information about the CLI, please read the cli section.

You can set the registry by using the following command.

npm set registry http://localhost:4873/

you can pass a --registry flag when needed.

npm install --registry http://localhost:4873

define in your .npmrc a registry field.

.npmrc

registry=http://localhost:4873

Or a publishConfig in your package.json

{
  "publishConfig": {
    "registry": "http://localhost:4873"
  }
}

Docker Image

docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio
Verdaccio

has an official docker image you can use, and in most cases, the default configuration is good enough. For more information about how to install the official image,

read the docker section

.

官方文档链接:https://verdaccio.org/zh-CN/docs/installation

### 配置 npm 的最佳实践 在 Node.js 环境下正确配置 npm开发过程中非常重要的一步。以下是关于设置代理、镜像源以及全局参数的具体方法。 #### 设置 npm 的镜像源 为了提高下载速度并减少网络延迟,可以将 npm 的默认注册表更改为国内的淘宝镜像。通过以下命令实现: ```bash npm config set registry https://registry.npmmirror.com ``` 此操作会更改 npm 的全局配置文件中的 `registry` 字段[^2]。如果需要验证当前使用的镜像源,可运行以下命令: ```bash npm get registry ``` #### 配置 HTTP/HTTPS 代理 在网络受限的情况下(例如公司内部网),可能需要配置 HTTP 或 HTTPS 代理来访问外部资源。可以通过如下命令完成代理设置: ```bash npm config set proxy http://proxy.company.com:8080 npm config set https-proxy http://proxy.company.com:8080 ``` 上述命令分别设置了 HTTP 和 HTTPS 协议下的代理地址。如果不需要代理或者想取消已有的代理设置,则执行以下命令即可清除代理配置: ```bash npm config delete proxy npm config delete https-proxy ``` #### 全局参数配置 某些情况下,开发者希望调整 npm 的行为以适应特定需求。常见的全局参数包括缓存目录位置和日志级别等。例如,修改缓存路径到自定义目录: ```bash npm config set cache "/path/to/custom/cache" ``` 此外,还可以降低或提升日志记录的详细程度以便于调试问题: ```bash npm config set loglevel warn ``` 以上命令将日志等级设为警告模式,仅显示错误和警告信息[^1]。 #### 总结 合理地配置 npm 不仅能优化依赖包管理效率,还能解决因地域差异带来的网络瓶颈等问题。按照上述指南进行相应设置后,能够显著改善基于 Node.js 开发项目的体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学亮编程手记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值