npm安装

centos7安装npm私有仓库

系统更新

yum update

安装node.js

#  安装gcc
yum install -y gcc-c++ make

# 下载包
cd /opt/
wget https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz

# 解压
tar -xf node-v16.13.0-linux-x64.tar.xz

# 链接
ln -s /opt/node-v16.13.0-linux-x64 /usr/local/node

# 添加系统变量
cat /etc/profile
NODE_PATH=/usr/local/node/bin
export PATH=$PATH:$NODE_PATH

# 配置生效
source /etc/profile

# 查看版本
[root@python opt]# node -v 
v16.13.0
[root@python opt]# npm -v
8.1.0

安装verdaccio

# 全局安装,使用淘宝源,注意2022年后变成以下路径
npm install -global verdaccio --registry=https://registry.npmmirror.com

# 查看安装目录
npm root -g

# 前台启动,默认端口4873,第一次启动会在当前用户家目录下生产.config/verdaccio/config.yaml配置文件,按ctrl+c停止
verdaccio

# 编辑配置文件
[root@python opt]# cat /root/.config/verdaccio/config.yaml  | egrep -v "^#"

storage: /mnt/rhd/storage     # 仓库存储文件
plugins: /mnt/rhd/plugins     # 插件目录

web:
  title: Verdaccio

auth:
  htpasswd:
    file: /mnt/rhd/htpasswd   # 用户密码文件,使用htpasswd创建用户

uplinks:
  npmjs:
    url: https://registry.npmjs.org/  #上游的npm服务器,使用国内源
 
packages:                             # 配置模块权限,access访问下载权限,publish发布权限
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: npmjs
    access: $all
    publish: $authenticated
    unpublish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs

server:
  keepAliveTimeout: 60
middlewares:
  audit:
    enabled: true

log: { type: stdout, format: pretty, level: http }

i18n:
   web: zh-CN                  # 修改中文界面
listen: 0.0.0.0:4873           # 监听地址端口

通过pm2启动verdaccio

npm install -g pm2 --registry=https://registry.npmmirror.com
pm2 start verdaccio
pm2 startup
pm2 save
systemctl  restart pm2-root.service

测试

### 安装htpasswd 命令
yum -y install httpd-tools-2.4.6-99.el7.centos.1.x86_64

### 创建admin用户并设置密码
#如果在config.yaml配置文件里权限设置为$all,则不用创建账户。但是登陆web界面需要用户密码
htpasswd -c /mnt/rhd/htpasswd admin

### 设置默认仓库
npm set registry http://192.168.150.12:4873

### 登录
npm login

### 创建一个包
mkdir npm-publish-test
cd npm-publish-test
npm init
# 每次提交前需要在package.json中国控制好包的版本号(version)
# 在包根目录下添加README.md,对包的使用进行说明(对同事友好一些)
# 添加.gitignore文件,别把没用的东西传上去
# 上传之前,最好将代码转译为es5低版本语法,不然别人引用你的包,在低端浏览器会报错
# 当然,如果你不想转化为es5,也不是不可以,使用者可以通过babel配置转译node_modules中的包,详细操作见下文 使用者下载包并使用 -> # 配置babel转译,兼容IE

### 发布包
npm publish	

### 网页登录查看
192.168.150.12:4873

# 也安装验证
npm install -g express

posted @   itk  阅读(21)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示