windows下安装本地化npm包管理服务 详细实例过程
创始人
2024-06-02 13:12:20
0

windows下安装本地化npm包管理服务

安装依赖包

  • 系统:windows 11,
  • npm服务器的包是:verdaccio@5.21.1
  • node:16.x
  • npm install verdaccio@5.x -g
  • 工作路径:d:\zdhsoft\verdaccio

配置文件

  • 在目录d:\zdhsoft\verdaccio新建一个配置文件config.yaml
  • 内容如下:
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
## path to a directory with all packages
storage: D:/zdhsoft/verdaccio/storage
# path to a directory with plugins to include
plugins: D:/zdhsoft/verdaccio/pluginsweb:title: zdhsoft NPM库# comment out to disable gravatar support# gravatar: # by default packages are ordercer ascendant (asc|desc)sort_packages: asc# convert your UI to the dark side# darkMode: true# 自己随便配置一个logo和faviconlogo: D:/zdhsoft/verdaccio/logo-white.pngfavicon: D:/zdhsoft/verdaccio/favicon.ico# favicon: http://somedomain/favicon.ico | /path/favicon.icopkgManagers:- npm- yarn# translate your registry, api i18n not available yet
i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translationsweb: zh-CNauth:htpasswd:file: D:/zdhsoft/verdaccio/htpasswd# Maximum amount of users allowed to register, defaults to "+inf".# You can set this to -1 to disable registration.max_users: -1max_body_size: 500mb# a list of other known repositories we can talk to
uplinks:npmjs:url: https://registry.npmjs.org/taobao:url: https://registry.npmmirror.com/packages:'@zdh/*':# scoped packagesaccess: $allpublish: $authenticatedunpublish: $authenticatedproxy: taobao 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: $authenticated# unpublish: $authenticated# if package is not available locally, proxy requests to 'npmjs' registryproxy: taobao npmjs# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:keepAliveTimeout: 60
listen: 0.0.0.0:4873
middlewares:audit:enabled: true# log settings
logs: { 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;
#  }# This affect the web and api (not developed yet)
#i18n:
#web: en-US

控制台下启动

  • 新建一个v.bat,也可以直接在控制台下面输入下面命令
  • 内容如下
verdaccio -c D:\zdhsoft\verdaccio\config.yaml

配置用户

  • 在控制台下,进入目录d:\zdhsoft\verdaccio
>d:
>cd D:\zdhsoft\verdaccio
>npm install htpasswd-for-sinopia -g
>sinopia-adduser
  • 按照提示输入用户名和密码 这个信息会存在当前的htpasswd的文件中
  • 然后启动verdaccio,再进入在浏览器 http://localhost:4873/
  • 就可以登录了,并可以通用这个用户发布你的定制npm包
  • 如果不是你想要的用户,可以用编辑器编辑htpasswd,删除你不要用户就可以了

安装服务

  • 这里使用的是工具是nssm 一个开源的工具 NSSM - the Non-Sucking Service Manager
  • 下载地址:https://www.nssm.cc/release/nssm-2.24.zip
  • 解压后,就可以看到有32位或64位的nssm命令
  • 然后在管理员的控制台下面:nssm install LocalNPMService
    • LocalNPMService 这个是你服务的名称,安装成功后,可以在windows带的服务管理看到这个服务名称
      -在这里插入图片描述

    • 填写信息:

      • path: node
      • Startup directory: d:\zdhsoft\verdaccio
      • Arguments: C:\Users\rex\AppData\Roaming\npm\node_modules\verdaccio\build\lib\cli.js -c D:\zdhsoft\verdaccio\config.yaml
    • 然后点击install service就可以了(其它的设置,可以有兴趣研究一下)

    • 最后在windows服务管理,就可以看到这个服务了

    • 在这里插入图片描述

最后

  • npm config set registry=http://localhost:4873 就可以用了

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
【Ctfer训练计划】——(三... 作者名:Demo不是emo  主页面链接:主页传送门 创作初心ÿ...