詳解Node.js利用node-git-server快速搭建git服務器
本文用到了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服務器沒有區(qū)別,簡直太簡單方便了?。?!
同樣git clone也比較簡單!
6、云端git倉庫的位置
在index.js中我們指定git倉庫存放在:const repos = new Server('/tmp/repos');目錄下
登錄遠程服務器可以發(fā)現(xiàn)在/tmp/repos/目錄下存在我們同步的git倉庫:(其中beep.git是之前push的一個)
╭─root@lt /tmp/repos ╰─# ls beautifulzzzz.git beep.git
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Node.js數(shù)據(jù)庫操作之查詢MySQL數(shù)據(jù)庫(二)
這篇文章主要介紹了Node.js數(shù)據(jù)庫操作之查詢MySQL數(shù)據(jù)庫的相關資料,文中介紹的非常詳細,對大家學習或者使用mysql能帶來一定的幫助,需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03使用nodejs+express實現(xiàn)簡單的文件上傳功能
這篇文章主要介紹了使用nodejs+express完成簡單的文件上傳功能,需要的朋友可以參考下2017-12-12如何使用Node.js爬取任意網(wǎng)頁資源并輸出PDF文件到本地
這篇文章主要介紹了使用Node.js爬取任意網(wǎng)頁資源并輸出高質量PDF文件到本地,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,下面小編就來和大家一起學習吧2019-06-06Node.js?中使用fetch?按JSON格式發(fā)post請求的問題解析
最近在測試一個api,可以用curl命令直接訪問,指定header相關配置,request?body(JSON),成功后返回一個JSON,這篇文章主要介紹了Node.js?中使用fetch?按JSON格式發(fā)post請求,需要的朋友可以參考下2023-04-04