Sinopia搭建私有的NPM服务
- NodeJS
- 2019-04-21 22:23:53
- 浏览 1275
简介Node.js开发本地项目,有时不同项目之间存在依赖,如果不想把项目发布到npm社区的仓库,则需要有自己本地的仓库环境准备Ubuntu18.04安装NodeJS安装NPM安装CNPM服务器配置安装sinopiacnpm install -g sinopia安装完毕后运行sinopia运行会输出如下,显示出当前配置文件和连接地址修改配置文件#
# This is the default config fil<!--autointro-->
Node.js开发本地项目,有时不同项目之间存在依赖,如果不想把项目发布到npm社区的仓库,则需要有自己本地的仓库
环境准备
Ubuntu18.04
安装NodeJS
安装NPM
安装CNPM
服务器配置
安装sinopia
cnpm install -g sinopia
安装完毕后运行
sinopia
运行会输出如下,显示出当前配置文件和连接地址
修改配置文件
# # 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/rlidwka/sinopia/tree/master/conf # # path to a directory with all packages storage: ./storage #npm包存放的路径 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: -1 #默认为1000,改为-1,禁止注册 # a list of other known repositories we can talk to uplinks: npmjs: url: http://registry.npm.taobao.org/ #默认为npm的官网,由于国情,修改 url 让sinopia使用 淘宝的npm镜像地址 packages: #配置权限管理 '@*/*': # scoped packages access: $all # 表示哪一类用户可以对匹配的项目进行安装 # $all 表示所有人都可以执行对应的操作, # $authenticated 表示只有通过验证的人可以执行对应操作, # $anonymous 表示只有匿名者可以进行对应操作(通常无用) publish: $authenticated #表示哪一类用户可以对匹配的项目进行发布 '*': # 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 packages # (anyone can register by default, remember?) publish: $authenticated #表示哪一类用户可以对匹配的项目进行发布 # if package is not available locally, proxy requests to 'npmjs' registry proxy: npmjs #如其名,这里的值是对应于 uplinks # log settings logs: - {type: stdout, format: pretty, level: http} #- {type: file, path: sinopia.log, level: info} # you can specify listen address (or simply a port) listen: 0.0.0.0:4873 #默认没有,只能在本机访问,添加后可以通过外网访问
使用pm2运行sinopia (守护进程)
npm install -g pm2 npm install -g sinopia-pm2-starter
开启服务
sinopia-pm2-starter --help # 查看帮助命令 sinopia-pm2-starter config:host '0.0.0.0' # 设置允许远程连接 sinopia-pm2-starter config:post ${port} # 不设置则默认4873 sinopia-pm2-starter start # 启动服务
客户端配置
使用nrm管理源(nrm是NPM的源切换利器)
npm install -g nrm # 安装nrm nrm add [name] http://XXXXXX:4873 # 添加本地的npm镜像地址 nrm use [name] # 使用本址的镜像地址 name为你要增加的地址
添加用户
npm adduser Username: test Password: test Email: (this IS public) xxx@xxxx
发布项目
npm publish
---------------后记---------------
如果不需要某个发布包了,可以进入服务器的NPM包存放目录直接删除即可。
暂时木有。