[Node.js] 2、利用node-git-server快速搭建git服务器
本文用到了node-git-server
1、检测本地git版本
该包的使用需要机器上本来就安装git,且git的版本大于等于2.7:
╭─root@lt /home/workspace
╰─# git --version ↵
git version 2.7.
2、利用npm安装包
╭─root@lt /home/workspace
╰─# npm install node-git-server
/home/workspace
└─┬ node-git-server@0.3.
├─┬ http-duplex@0.0.
│ ├── duplex-pipe@0.0.
│ └── inherits@1.0.
└── through@2.3. 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
:: 如果您觉得不错,请推荐给更多人,帮助他们更快地解决实际问题中的坑~
@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
园友交流群:414948975
[Node.js] 2、利用node-git-server快速搭建git服务器的更多相关文章
- 【Node.js】利用node.js搭建服务器并访问静态网页
node.js是一门服务端的语言,下面讲讲如何利用node.js提供给我们的api来搭建服务器,并且访问静态网页 项目结构如下 ------------------------------------ ...
- Node.js 从零开发 web server博客项目[express重构博客项目]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[数据存储]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[koa2重构博客项目]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[安全]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[日志]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[登录]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[接口]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[项目介绍]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js入门:Node.js&NPM的安装与配置
Node.js安装与配置 Node.js已经诞生两年有余,由于一直处于快速开发中,过去的一些安装配置介绍多数针对0.4.x版本而言的,并非适合最新的0.6.x的版本情况了,对此,我们将在0. ...
随机推荐
- VS2015 安装nuget离线包nupkg文件
最近在做项目进度管理时,想通过安装net.sf.mpxj-for-csharp包读取.mpp格式文件,通过Nuget在线安装时,出现以下情况,无法安装,故开启离线安装道路. 离线安装步骤如下: 一.下 ...
- go web 第一天 学习笔记
package main import ( "fmt" "log" "net/http" "strings" ) fun ...
- java web开发时的绝对路径与相对路径
相对路径 不以/开头的路径为相对路径,使用相对路径时的路径为当前访问的文件的父目录,即如果现在访问文件的路径为http://localhost:8080/项目名/目录/文件,那么使用相对路径时路径前缀 ...
- What is the difference between Debug and Release in Visual Studio?
"Debug" and "Release" are actually just two labels for a whole slew of settings ...
- php 数据访问练习:租房查询页面
<html> <head> <title></title> <meta charset="UTF-8"/> <li ...
- spring-session 共享
Spring session 共享 一.引入依赖 <dependency> <groupId>redis.clients</groupId> <artifac ...
- python requests 官方文档
链接:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
- Mysql only_full_group_by以及其他关于sql_mode原因报错详细解决方案
Mysql only_full_group_by以及其他关于sql_mode原因报错详细解决方案 网上太多相关资料,但是抄袭严重,有的讲的也是之言片语的,根本不连贯(可能知道的人确实不想多说) 我总共 ...
- 使用反射+策略模式代替项目中大量的switch case判断
我这里的业务场景是根据消息类型将离线消息存入mongoDB不同的collection中.其中就涉及到大量的分支判断,为了增强代码的可读性和可维护性,对之前的代码进行了重构. 先对比一下使用反射+策略模 ...
- eval浅解
关于eval,你了解多少呢?来看看 eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 需要一个参数(string),切必需.要计算的字符串,其中含有要计算的 JavaS ...