详解Node.js利用node-git-server快速搭建git服务器
2017-09-27 08:31
776 查看
本文用到了node-git-server
1、检测本地git版本
该包的使用需要机器上本来就安装git,且git的版本大于等于2.7:
╭─root@lt /home/workspace ╰─# git --version git version 2.7.4
2、利用npm安装包
╭─root@lt /home/workspace ╰─# npm install node-git-server /home/workspace └─┬ node-git-server@0.3.0 ├─┬ http-duplex@0.0.2 │ ├── duplex-pipe@0.0.2 │ └── inherits@1.0.2 └── through@2.3.8 npm WARN enoent ENOENT: no such file or directory, open '/home/workspace/package.json' npm WARN workspace No description npm WARN workspace No repository field. npm WARN workspace No README data npm WARN workspace No license field.
有警告可以先忽略~
3、编写example
cd ./node_modules/node-git-server/example/
编辑index.js
const Server = require('node-git-server'); const repos = new Server('/tmp/repos'); const port = process.env.PORT || 80; repos.on('push', (push) => { console.log('push ' + push.repo + '/' + push.commit + ' (' + push.branch + ')' ); push.accept(); }); repos.on('fetch', (fetch) => { console.log('fetch ' + fetch.commit); fetch.accept(); }); repos.listen(port, () => { console.log(`node-git-server running at http://localhost:${port}`) });
4、运行
╭─root@lt /home/workspace/node_modules/node-git-server/example ╰─# node index.js node-git-server running at http://localhost:80
5、测试git服务器
由于我的git服务器是在aliyun上跑的,并且绑定了www.beautifulzzzz.com,所以我先在本地新建一个git仓库,并将其推送同步到云端,然后再clone下来来做测试:
可见将本地git仓库同步到云端和普通的git服务器没有区别,简直太简单方便了!!!
同样git clone也比较简单!
6、云端git仓库的位置
在index.js中我们指定git仓库存放在:const repos = new Server('/tmp/repos');目录下
登录远程服务器可以发现在/tmp/repos/目录下存在我们同步的git仓库:(其中beep.git是之前push的一个)
╭─root@lt /tmp/repos ╰─# ls beautifulzzzz.git beep.git
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章推荐
- [Node.js] 2、利用node-git-server快速搭建git服务器
- mac os 利用ssh 搭建git server服务器详细教程,以及git基本用法
- mac os 利用ssh 搭建git server服务器详细教程,以及git基本用法(上)
- 使用Node.js快速搭建WebSocket server
- 利用node.js如何搭建一个简易的即时响应服务器
- mac os 利用ssh 搭建git server服务器详细教程,以及git基本用法(下)
- 教你快速搭建Node.Js服务器的方法教程
- mac os 利用ssh 搭建git server服务器详细教程,以及git基本用法(上)
- Node.js快速搭建服务器
- 利用node.js+mongodb如何搭建一个简单登录注册的功能详解
- 利用node.js搭建简单web服务器的方法教程
- 利用doker快速搭建node.js运行环境
- 使用Node.js快速搭建WebSocket server
- mac os 利用ssh 搭建git server服务器详细教程,以及git基本用法(下)
- 利用Node.js对某智能家居服务器重构
- 快速使用node.js进行web开发详解
- SSH+Git Server on Windows - 在Windows下搭建Git服务器(教程)
- 建立一个node.js服务器(使用express搭建第一个Web环境)
- 在腾讯云(windows)上搭建node.js服务器
- node.js搭建服务器