当前位置: 首页 > news >正文

ubuntu20.04上使用 Verdaccio 搭建 npm 私有仓库

安装nvm

  1. 首先安装必要的工具:
apt update
apt install curl
  1. 下载并执行nvm安装脚本:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  1. 添加环境变量(如果安装脚本没有自动添加)。编辑 ~/.bashrc:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  1. 使环境变量生效:
source ~/.bashrc
  1. 验证安装:
nvm --version

常用nvm命令:

nvm install node        # 安装最新版node
nvm install 20.18.0    # 安装特定版本
nvm use 20.18.0        # 使用特定版本
nvm ls                 # 列出已安装的版本
nvm current            # 显示当前使用的版本
nvm alias default 20.18.0  # 设置默认版本

如果遇到网络问题,可以设置淘宝镜像:

export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node

安装 Verdaccio

# 必须要加 -g 全局安装
npm install verdaccio -g

安装成功之后随即在命令行输出 verdaccio 随即我们会看到服务已经运行;出现以下内容

v1.png

根据服务启动后信息不难得到两个重要信息

verdaccio 配置文件:/root/.config/verdaccio/config.yaml

verdaccio 默认启动:默认占用 4873 端口(使用云服务器的小伙伴记得开启安全组)。

注意: 可能有些小伙伴的启用端口前面显示的是 localhost:4873,如果出现这种情况打开安全组也是不生效的,以下附上解决方案。

使用 vim 打开配置文件。在首行新增 listen 0.0.0.0:4873,端口可以任意指定。0.0.0.0 就是表示当前主机的 IPV4 地址;之后再重启服务就,在浏览器输入服务器 IP 加端口就可以访问了。

我的/root/.config/verdaccio/config.yaml 配置文件:

listen: 0.0.0.0:4873
# path to a directory with all packages
storage: /home/lzq/.local/share/verdaccio/storage
# path to a directory with plugins to include
plugins: ./plugins
# 添加以下配置来增加最大包体积限制
max_body_size: 1000mb# https://verdaccio.org/docs/webui
web:title: Verdaccio# comment out to disable gravatar support# gravatar: false# by default packages are ordercer ascendant (asc|desc)# sort_packages: asc# convert your UI to the dark side# darkMode: true# html_cache: true# by default all features are displayed# login: true# showInfo: true# showSettings: true# In combination with darkMode you can force specific theme# showThemeSwitch: true# showFooter: true# showSearch: true# showRaw: true# showDownloadTarball: true#  HTML tags injected after manifest <scripts/># scriptsBodyAfter:#    - '<script type="text/javascript" src="https://my.company.com/customJS.min.js"></script>'#  HTML tags injected before ends </head>#  metaScripts:#    - '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>'#    - '<script type="text/javascript" src="https://browser.sentry-cdn.com/5.15.5/bundle.min.js"></script>'#    - '<meta name="robots" content="noindex" />'#  HTML tags injected first child at <body/>#  bodyBefore:#    - '<div id="myId">html before webpack scripts</div>'#  Public path for template manifest scripts (only manifest)#  publicPath: http://somedomain.org/# https://verdaccio.org/docs/configuration#authentication
auth:htpasswd:file: ./htpasswd# Maximum amount of users allowed to register, defaults to "+inf".# You can set this to -1 to disable registration.# max_users: 1000# Hash algorithm, possible options are: "bcrypt", "md5", "sha1", "crypt".# algorithm: bcrypt # by default is crypt, but is recommended use bcrypt for new installations# Rounds number for "bcrypt", will be ignored for other algorithms.# rounds: 10# https://verdaccio.org/docs/configuration#uplinks
# a list of other known repositories we can talk to
uplinks:npmjs:url: https://registry.npmmirror.com/maxage: 30mtimeout: 600smax_fails: 5fail_timeout: 5mcache: true# Learn how to protect your packages
# https://verdaccio.org/docs/protect-your-dependencies/
# https://verdaccio.org/docs/configuration#packages
packages:'@*/*':# scoped packagesaccess: $allpublish: $authenticatedunpublish: $authenticatedproxy: npmjs'**':# allow all users (including non-authenticated users) to read and# publish all packages## you can specify usernames/groupnames (depending on your auth plugin)# and three keywords: "$all", "$anonymous", "$authenticated"access: $all# allow all known users to publish/publish packages# (anyone can register by default, remember?)publish: $authenticatedunpublish: $authenticated# if package is not available locally, proxy requests to 'npmjs' registryproxy: npmjsserver:keepAliveTimeout: 60timeout: 600000rateLimit:windowMs: 1000max: 10000bodyParser:json:limit: '1000mb'    # JSON请求体积限制encoded:limit: '1000mb'    # URL编码请求体积限制# Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer# See: https://expressjs.com/en/guide/behind-proxies.html# trustProxy: '127.0.0.1'# https://verdaccio.org/docs/configuration#offline-publish
# publish:
#   allow_offline: false# https://verdaccio.org/docs/configuration#url-prefix
# url_prefix: /verdaccio/
# VERDACCIO_PUBLIC_URL='https://somedomain.org';
# url_prefix: '/my_prefix'
# // url -> https://somedomain.org/my_prefix/
# VERDACCIO_PUBLIC_URL='https://somedomain.org';
# url_prefix: '/'
# // url -> https://somedomain.org/
# VERDACCIO_PUBLIC_URL='https://somedomain.org/first_prefix';
# url_prefix: '/second_prefix'
# // url -> https://somedomain.org/second_prefix/'# security:
#   api:
#     legacy: true
#     # recomended set to true for older installations
#     migrateToSecureLegacySignature: true
#     jwt:
#       sign:
#         expiresIn: 29d
#       verify:
#         someProp: [value]
#    web:
#      sign:
#        expiresIn: 1h # 1 hour by default
#      verify:
#         someProp: [value]# https://verdaccio.org/docs/configuration#user-rate-limit
# userRateLimit:
#   windowMs: 50000
#   max: 1000# https://verdaccio.org/docs/configuration#max-body-size
# max_body_size: 10mb# https://verdaccio.org/docs/configuration#listen-port
# listen:
# - localhost:4873            # default value
# - http://localhost:4873     # same thing
# - 0.0.0.0:4873              # listen on all addresses (INADDR_ANY)
# - https://example.org:4873  # if you want to use https
# - "[::1]:4873"                # ipv6
# - unix:/tmp/verdaccio.sock    # unix socket# The HTTPS configuration is useful if you do not consider use a HTTP Proxy
# https://verdaccio.org/docs/configuration#https
# https:
#   key: ./path/verdaccio-key.pem
#   cert: ./path/verdaccio-cert.pem
#   ca: ./path/verdaccio-csr.pem# https://verdaccio.org/docs/configuration#proxy
# http_proxy: http://something.local/
# https_proxy: https://something.local/# https://verdaccio.org/docs/configuration#notifications
# notify:
#   method: POST
#   headers: [{ "Content-Type": "application/json" }]
#   endpoint: https://usagge.hipchat.com/v2/room/3729485/notification?auth_token=mySecretToken
#   content: '{"color":"green","message":"New package published: * {{ name }}*","notify":true,"message_format":"text"}'middlewares:audit:enabled: true# https://verdaccio.org/docs/logger
# log settings
log: { type: stdout, format: pretty, level: http }
#experiments:
#  # support for npm token command
#  token: false
#  # disable writing body size to logs, read more on ticket 1912
#  bytesin_off: false
#  # enable tarball URL redirect for hosting tarball with a different server, the tarball_url_redirect can be a template string
#  tarball_url_redirect: 'https://mycdn.com/verdaccio/${packageName}/${filename}'
#  # the tarball_url_redirect can be a function, takes packageName and filename and returns the url, when working with a js configuration file
#  tarball_url_redirect(packageName, filename) {
#    const signedUrl = // generate a signed url
#    return signedUrl;
#  }# translate your registry, api i18n not available yet
# i18n:
# list of the available translations https://github.com/verdaccio/verdaccio/blob/master/packages/plugins/ui-theme/src/i18n/ABOUT_TRANSLATIONS.md
#   web: en-US

使用 pm2 管理 verdaccio

此时我们虽然能够访问到 npm 私服,但是有个很严重的问题,就是启动服务后在命令行中不能进行其他操作。这里推荐使用 pm2 对 verdaccio 进程进行管理。即使退出 ssh 连接也能在后台运行。

# 全局安装 verdaccio和pm2
$ npm install -g pm2
$ pm2 start verdaccio
[PM2] Starting /usr/local/bin/verdaccio in fork_mode (1 instance)
[PM2] Done.
┌─────┬──────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name         │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ verdaccio    │ default     │ N/A     │ fork    │ 20889    │ 0s     │ 0    │ online    │ 0%       │ 10.2mb   │ cm       │ disabled │
└─────┴──────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

常用命令

指令	  描述	                                    示例
pm2 -ls	  列出当前被 pm2 管理的所有进程	
pm2 stop  <app_name | namespace|id|'all'|json_conf>	关闭某个进程	pm2 stop vardaccio
pm2 restart <app_name|namespace|id|'all'|json_conf>	重启某个进程	pm2 restart verdaccio
pm2 delete <app_name|namespace|id]|'all'|json_conf>	删除某个进程	pm2 delete verdaccio
pm2 start <app_name|namespace|id|'all'|json_conf>	启动某个进程	pm2 start verdaccio

nrm 管理 npm 源

npm install -g nrm
# 添加私有库
$ nrm add localnpm http://服务器ip:4873# 查看现有的npm源
$ 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/localnpm -- http://服务器ip:4873/
# 设置npm源
$ nrm use localnpm 

发布包到私有库上

注册用户

# 注册用户
$ npm adduser
npm notice Log in on http://服务器ip:4873/
Username: yourusername
Password:
Email: (this IS public) xxxxxx@qq.com
Logged in as yourusername on http://服务器ip:4873/.

登录

# 登录用户
$ npm login
npm notice Log in on http://服务器ip:4873/
Username: yourusername
Password:
Email: (this IS public) xxxxxx@qq.com
Logged in as yourusername on http://服务器ip:4873/.
# 查看当前登录用户
$ npm who am i
yourusername

发布
进入含有package.json的目录,执行命令

# 发布当前包
$ npm publish
...
npm notice === Tarball Details ===
npm notice name:          marriage-service-manage
npm notice version:       3.2.1
npm notice package size:  11.9 MB
npm notice unpacked size: 22.3 MB
npm notice shasum:        cb0cb1535cedd1a36edb070d10829fb5fb1213ef
npm notice integrity:     sha512-WV65rERQZZona[...]iRNAtK7Kz+cxg==
npm notice total files:   725
npm notice
+ marriage-service-manage@3.2.1
# 最后看到 + [你的包名@版本号]既可

相关文章:

ubuntu20.04上使用 Verdaccio 搭建 npm 私有仓库

安装nvm 首先安装必要的工具&#xff1a; apt update apt install curl下载并执行nvm安装脚本&#xff1a; curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash添加环境变量&#xff08;如果安装脚本没有自动添加&#xff09;。编辑 ~/.bash…...

Python实现办公自动化的数据可视化与报表生成

在 Python 中&#xff0c;可以利用多个库来实现办公自动化中的数据可视化与报表生成。以下是具体的方法&#xff1a; 一、数据可视化 使用 matplotlib 库 matplotlib 是一个强大的 Python 绘图库&#xff0c;可以创建各种类型的静态、动态和交互式图表。示例代码&#xff1a;i…...

前端知识串联笔记(更新中...)

1.MVVM MVVM 是指 Model - View - ViewModel&#xff0c;Model 是数据与业务逻辑&#xff0c;View 是视图&#xff0c;ViewModel 用于连接 View 和 Model Model ---> View&#xff1a;将数据转化成所看到的页面&#xff0c;实现的方式&#xff1a;Data Bindings -- 数据绑定…...

PostgreSQL根据字符串的长度排序

PostgreSQL根据字符串的长度排序 在 PostgreSQL 中&#xff0c;你可以使用 LENGTH 函数来获取字符串的长度&#xff0c;并根据这个长度进行排序。LENGTH 函数会返回字符串的字符数。 以下是一个基本的 SQL 查询示例&#xff0c;它根据 some_column 字符串列的长度对表中的行进…...

计算机网络:网络层 —— IP数据报的发送和转发过程

文章目录 IP数据报的发送和转发过程主机发送IP数据报路由器转发IP数据报示例 IP数据报的发送和转发过程 IP 数据报的发送和转发过程包含以下两个过程&#xff1a; 主机发送IP数据报路由器转发IP数据报 直接交付&#xff1a;源主机与目的主机在同一网络中间接交付&#xff1a;…...

【算力基础】GPU算力计算和其他相关基础(TFLOPS/TOPS/FP32/INT8...)

文章目录 :one: 算力的常见指标:two: 算力计算:three: 常用链接 &#x1f680; 本文主要是聚焦于深度学习领域的 GPU的算力估计&#xff0c;其他类型的硬件设备如CPU可以类比参考。 1️⃣ 算力的常见指标 算力衡量主要与运算速度和精度这两个指标有关。 &#x1f314;速度指…...

UI自动化测试(app端)4.0

✨博客主页&#xff1a; https://blog.csdn.net/m0_63815035?typeblog &#x1f497;《博客内容》&#xff1a;.NET、Java.测试开发、Python、Android、Go、Node、Android前端小程序等相关领域知识 &#x1f4e2;博客专栏&#xff1a; https://blog.csdn.net/m0_63815035/cat…...

C#与C++交互开发系列(十):数组传递的几种形式

前言 在C#和C的交互开发中&#xff0c;数组传递是一个非常常见且实用的场景。数组可以作为方法的参数&#xff0c;也可以作为响应结果返回。在本篇博客中&#xff0c;我们将探讨几种常见的数组传递方式&#xff0c;展示如何在C#与C之间进行有效的数据交换。我们将主要介绍以下…...

【C++复习】第一弹-基础性语法

前言 学习了C语法这么久了&#xff0c;我其实觉得&#xff0c;我们学习一门语言应该更加注重使用性&#xff0c;对于语法的细节可以通过具体的项目去重新造轮子的时候再去抠细节&#xff0c;也就是说你得学会先走&#xff0c;在去想我们如何走的&#xff0c;身体的哪些肌肉在发…...

软考高级备考记录

一 报考条件和报名流程 报考条件 该考试具有水平考试性质&#xff0c;报考任何级别不需要学历、资历条件&#xff0c;只要达到相应的专业技术水平就可以报考相应的级别 报名流程 软考报名官网&#xff1a;中国计算机技术职业资格网 官网上有 报名时间&#xff0c;考试…...

图为大模型一体机新探索,赋能智能家居行业

在21世纪的今天&#xff0c;科技的飞速进步正以前所未有的速度重塑着我们的生活方式。从智能手机到物联网&#xff0c;从大数据到人工智能&#xff0c;每一项技术创新都在为人类带来前所未有的便利与效率。其中&#xff0c;图为AI大模型一体机作为人工智能领域的最新成果&#…...

精氨酸/赖氨酸多肽(芋螺肽)

产品简介&#xff1a; 芋螺肽&#xff0c;源自瑞士尖端科技&#xff0c;是一种模拟芋螺毒素的生物活性肽。它以其独特的分子结构和高选择性作用于电压门控钠离子通道&#xff08;特别是Nav1.4&#xff09;&#xff0c;为您提供安全、自然且不僵硬的回春效果。芋螺肽&#xff0…...

C++音视频04:音视频编码、生成图片

视频编码 #include <libavutil/log.h> #include <libavutil/opt.h> #include <libavcodec/avcodec.h>static int encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *out) {int ret -1;ret avcodec_send_frame(ctx, frame);if (ret < …...

ImageSharp报错

错误信息 System.MissingMethodException: Method not found: System.Span1<SixLabors.ImageSharp.PixelFormats.Rgba32> SixLabors.ImageSharp.Memory.Buffer2D1.GetRowSpan(Int32).需要升级项目 原来仅升级了SixLabors.ImageSharp没有升级drawing&#xff0c;都升级到…...

Android中常用adb命令

目录 1.adb连接安卓模拟器 2.adb列出所有已经连接的设备 3.adb显示设备的日志信息 4.adb 电脑文件推送到安卓模拟器中 5.adb 手机传送文件到电脑 6.adb获取安卓应用的包名和Activity名 附录 1--命令 1&#xff09;adb devices 2&#xff09;adb install 路径> 3&#xff09;…...

PostgreSQL的奥秘:全面解读JSONB——非结构化数据支持的深入探索

引言 PostgreSQL的JSONB数据类型非常灵活&#xff0c;提供了一套操作符来操作JSON数据。本指南将引导您创建一个包含JSONB数据的表&#xff0c;演示各种JSONB操作符&#xff0c;并讨论如何使用倒排索引和部分索引来优化性能。 理解PostgreSQL中的JSONB JSONB&#xff0c;即JS…...

tornado,flaskd这两个框架主要是干什么的

Tornado是一个Python的Web框架&#xff0c;主要用于构建高性能的异步Web应用程序。它基于非阻塞的网络I/O模型&#xff0c;可以处理大量并发连接&#xff0c;适用于需要处理实时性要求较高的应用场景&#xff0c;如实时聊天、实时数据推送等。 Flask是另一个Python的Web框架&a…...

Sigrity Power SI Noise coupling analysis模式如何进行压降仿真分析操作指导

Sigrity Power SI Noise coupling analysis模式如何进行压降仿真分析操作指导 Sigrity除了可以进行交流噪声分析,同样也可以进行压降仿真分析,以下图为例. 3D view...

国产游戏技术能否引领全球?

国产游戏技术能否引领全球&#xff1f; 引言 近年来&#xff0c;中国游戏产业如同春天的嫩芽&#xff0c;迅速成长为全球最大的市场之一。或许你会想&#xff0c;国内的游戏开发者到底在技术上取得了多大的成就&#xff1f;这些成就又能否推动中国游戏走向世界&#xff0c;甚…...

【前端】在 Next.js 开发服务器中应该如何配置 HTTPS?

在 Next.js 的开发环境中&#xff0c;默认情况下是使用 HTTP 协议的。但是&#xff0c;您可以通过一些配置来启用 HTTPS。这在开发阶段可能很有用&#xff0c;尤其是在需要测试涉及安全传输的应用场景时。 下面是如何在 Next.js 开发环境中配置 HTTPS 的步骤&#xff1a; 方法…...

易语言实现阶乘与组合数计算

是的&#xff0c;我听说过易语言&#xff0c;它是一款面向中文使用者的编程语言&#xff0c;以其直观的中文语法和图形化界面开发能力而著称。 一、 数学概念解析 在深入编程实现前&#xff0c;我们先明确两个基础的数学概念。 1. 阶乘 阶乘 是所有小于及等于该数的正整数的…...

避坑指南:Cypress CYT4B的Mcal CAN配置,这5个参数配错直接通信失败

Cypress CYT4B的Mcal CAN配置实战&#xff1a;5个致命参数解析与避坑策略 实验室里&#xff0c;示波器上的CAN波形杂乱无章&#xff0c;工程师反复检查硬件连接却始终无法建立稳定通信——这可能是许多嵌入式开发者调试CYT4B系列芯片时的真实写照。当硬件排查无果后&#xff0c…...

高分辨率路面缺陷检测数据集:道路健康状态自动监测的关键资源

路面缺陷检测数据集yolo掌握道路健康状态对于维护和规划都至关重要。 本数据集精选6100张高清图像&#xff0c;专门标注了道路表面的四种常见缺陷&#xff0c;包括鳄鱼状裂纹、横向裂纹、纵向裂纹和坑洞&#xff0c;旨在为道路维护和自动化检测提供强有力的数据支持。 图像集已…...

G-Helper:华硕笔记本电池健康管理的终极轻量化解决方案

G-Helper&#xff1a;华硕笔记本电池健康管理的终极轻量化解决方案 【免费下载链接】g-helper Lightweight Armoury Crate alternative for Asus laptops. Control tool for ROG Zephyrus G14, G15, G16, M16, Flow X13, Flow X16, TUF, Strix, Scar and other models 项目地…...

别再花钱买云API了!手把手教你用Docker+Ollama在本地免费跑通Strix渗透测试

零成本打造企业级渗透测试环境&#xff1a;DockerOllama本地化实战指南 当安全团队每月收到云服务商五位数的API账单时&#xff0c;当关键测试任务因网络抖动被迫中断时&#xff0c;越来越多的技术决策者开始重新审视渗透测试的基础架构。本文将揭示如何用消费级硬件构建媲美商…...

Llama-3.2-3B效果体验:Ollama简单操作,产出专业级文案

Llama-3.2-3B效果体验&#xff1a;Ollama简单操作&#xff0c;产出专业级文案 1. 模型概览&#xff1a;小而精的文本生成专家 Llama-3.2-3B是Meta最新推出的轻量级语言模型&#xff0c;在3B参数规模下实现了接近大模型的文本生成质量。经过指令微调优化后&#xff0c;它在多语…...

LangChainJS性能优化:大规模AI应用的高效处理指南

LangChainJS性能优化&#xff1a;大规模AI应用的高效处理指南 【免费下载链接】langchainjs 项目地址: https://gitcode.com/GitHub_Trending/la/langchainjs LangChainJS是一个强大的JavaScript/TypeScript框架&#xff0c;专门用于构建基于大语言模型&#xff08;LLM…...

Java AI开发避坑!

文章目录一、当"龙虾"突然发狂二、解剖这场"史诗级翻车"第一刀&#xff1a;插件生态大迁徙第二刀&#xff1a;API 接口一锅端第三刀&#xff1a;安全沙箱锁死第四刀&#xff1a;目录结构洗牌三、Java 开发者的至暗时刻WebSocket 连接闪断MCP 适配器失效技能…...

STM32CubeMX+Keil MDK联合开发:手把手教你配置蓝桥杯G431工程模板

STM32CubeMXKeil MDK联合开发&#xff1a;手把手教你配置蓝桥杯G431工程模板 对于参加蓝桥杯嵌入式赛道的选手来说&#xff0c;掌握STM32G431RBT6开发板的快速工程搭建是必备技能。本文将带你从零开始&#xff0c;通过STM32CubeMX和Keil MDK的协同工作&#xff0c;完成一个标准…...

OpenClaw异常处理手册:百川2-13B任务失败排查全攻略

OpenClaw异常处理手册&#xff1a;百川2-13B任务失败排查全攻略 1. 为什么需要这份手册 上周我尝试用OpenClaw百川2-13B模型自动处理日报生成任务时&#xff0c;连续三天凌晨任务失败。每次起床看到控制台的红色错误提示&#xff0c;都要花半小时翻日志找原因。最崩溃的是&am…...