安裝 Node
Linux中安裝Node
安裝verdaccio
npm i -g verdaccio
安裝完成 輸入verdaccio,出現(xiàn)下面信息代表安裝成功,同時輸入verdaccio后verdaccio已經(jīng)處于運行狀態(tài),當然這種啟動時暫時的,我們需要通過pm2讓verdaccio服務常駐
yg@iZ2zec61wsgbo9t9i346jbZ:~$ verdaccio
warn --- config file - /home/yg/.config/verdaccio/config.yaml
warn --- Plugin successfully loaded: htpasswd
warn --- Plugin successfully loaded: audit
warn --- http address - http://localhost:4873/ - verdaccio/3.10.1
配置config.yaml
1、vim /home/yg/.config/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: ./storage
# path to a directory with plugins to include
# 插件目錄
plugins: ./plugins
# 開啟web服務,能夠通過web訪問
web:
# WebUI is enabled as default, if you want disable it, just uncomment this line
#enable: false
title: Verdaccio
# 驗證信息
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
# a list of other known repositories we can talk to
# 公有倉庫配置
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'@*/*':
# scoped packages
access: $all
publish: $authenticated
# 代理,表示沒有的倉庫去這個npmjs里邊去找
# npmjs 又指向 https://registry.npmjs.org/ ,就是上面的 uplinks 配置
proxy: 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"
# 三種身份所有人,匿名用戶,認證(登錄用戶)
# 是否可訪問所需的權(quán)限
access: $all
# allow all known users to publish packages
# (anyone can register by default, remember?)
# 發(fā)布package的權(quán)限
publish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
# 如果package不存在,就向代理的上游服務器發(fā)起請求
proxy: npmjs
# To use `npm audit` uncomment the following section
middlewares:
audit:
enabled: true
# 監(jiān)聽端口,重點,不配置這個只能本機可以訪問
listen: 0.0.0.0:4873
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: verdaccio.log, level: info}
安裝 pm2
npm i pm2 -g
啟動
pm2 start verdaccio
就可以通過http://xxx(ip地址)去訪問了
若無法訪問,查看下端口是否已打開
#查看防火墻規(guī)則
firewall-cmd --list-all
#查詢端口是否開放
firewall-cmd --query-port=4873/tcp(默認端口,可以自定義)
#開放4873端口
firewall-cmd --permanent --add-port=4873/tcp (默認端口,可以自定義)
#重新載入
firewall-cmd --reload
阿里云服務器請開放安全組端口
設(shè)置 npm 服務指向本地
npm config set registry http://localhost:4873
注冊用戶
# 注冊用戶 在本地注冊一個用戶然后指向我們的地址然后我們就可以發(fā)布包了
npm adduser --registry http://xxx:4873
Username: xxx
Password: xxx
Password: xxx
Email: (this IS public) xxx
Logged in as yg-ui on http://xxx/ (你的ip地址)
這時候我們就注冊一個用戶,我們可以用這個用戶名和密碼去登錄去上圖窗口去登錄了
登錄
npm login # 用剛剛注冊的用戶名密碼進行登錄
npm whoami # 查看當前登錄的賬號
發(fā)包
mkdir npm-publish-test # 包文件夾
cd npm-publish-test
npm init # npm初始化
npm publish
刪除 指定版本或包
$ npm unpublish [<pkg>][@<version>] --force
下面列一下幾種使用場景
-
$ npm unpublish dzmtest@1.0.1 --force
直接強制刪除指定包的指定版本,不需要 cd 進入包文件夾內(nèi),隨處可以執(zhí)行。文章來源:http://www.zghlxwxcb.cn/news/detail-633894.html -
$ npm unpublish dzmtest --force
直接強制刪除指定包,不需要 cd 進入包文件夾內(nèi),隨處可以執(zhí)行。文章來源地址http://www.zghlxwxcb.cn/news/detail-633894.html
到了這里,關(guān)于Linux 中使用 verdaccio 搭建私有npm 服務器的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!