源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

详解Node.js利用node-git-server快速搭建git服务器

  • 时间:2022-06-15 03:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:详解Node.js利用node-git-server快速搭建git服务器
本文用到了[url=https://www.npmjs.com/package/node-git-server]node-git-server[/url] [b]1、检测本地git版本[/b] 该包的使用需要机器上本来就安装git,且git的版本大于等于2.7:
 ╭─root@lt /home/workspace 
 ╰─# git --version             
 git version 2.7.4
[b]2、利用npm安装包[/b]
╭─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.
有警告可以先忽略~ [b]3、编写example[/b] 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}`)
});

[b]4、运行[/b]
 ╭─root@lt /home/workspace/node_modules/node-git-server/example 
 ╰─# node index.js 
 node-git-server running at http://localhost:80
[b]5、测试git服务器[/b] 由于我的git服务器是在aliyun上跑的,并且绑定了www.beautifulzzzz.com,所以我先在本地新建一个git仓库,并将其推送同步到云端,然后再clone下来来做测试: [img]http://files.jb51.net/file_images/article/201709/201709270837074.jpg?201782783754[/img] 可见将本地git仓库同步到云端和普通的git服务器没有区别,简直太简单方便了!!! [img]http://files.jb51.net/file_images/article/201709/201709270837073.jpg?201782783818[/img] 同样git clone也比较简单! [b]6、云端git仓库的位置[/b] 在index.js中我们指定git仓库存放在:const repos = new Server('/tmp/repos');目录下 登录远程服务器可以发现在/tmp/repos/目录下存在我们同步的git仓库:(其中beep.git是之前push的一个)
 ╭─root@lt /tmp/repos 
 ╰─# ls
 beautifulzzzz.git beep.git
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部