詳解Node.js利用node-git-server快速搭建git服務(wù)器
本文用到了node-git-server
1、檢測本地git版本
該包的使用需要機(jī)器上本來就安裝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、運(yùn)行
╭─root@lt /home/workspace/node_modules/node-git-server/example ╰─# node index.js node-git-server running at http://localhost:80
5、測試git服務(wù)器
由于我的git服務(wù)器是在aliyun上跑的,并且綁定了www.beautifulzzzz.com,所以我先在本地新建一個(gè)git倉庫,并將其推送同步到云端,然后再clone下來來做測試:
可見將本地git倉庫同步到云端和普通的git服務(wù)器沒有區(qū)別,簡直太簡單方便了?。?!
同樣git clone也比較簡單!
6、云端git倉庫的位置
在index.js中我們指定git倉庫存放在:const repos = new Server('/tmp/repos');目錄下
登錄遠(yuǎn)程服務(wù)器可以發(fā)現(xiàn)在/tmp/repos/目錄下存在我們同步的git倉庫:(其中beep.git是之前push的一個(gè))
╭─root@lt /tmp/repos ╰─# ls beautifulzzzz.git beep.git
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Node.js數(shù)據(jù)庫操作之查詢MySQL數(shù)據(jù)庫(二)
這篇文章主要介紹了Node.js數(shù)據(jù)庫操作之查詢MySQL數(shù)據(jù)庫的相關(guān)資料,文中介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用mysql能帶來一定的幫助,需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03Nest.js使用multer實(shí)現(xiàn)文件上傳功能
這篇文章主要為大家詳細(xì)介紹了Nest.js鵝湖使用multer實(shí)現(xiàn)文件上傳功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03使用nodejs+express實(shí)現(xiàn)簡單的文件上傳功能
這篇文章主要介紹了使用nodejs+express完成簡單的文件上傳功能,需要的朋友可以參考下2017-12-12如何使用Node.js爬取任意網(wǎng)頁資源并輸出PDF文件到本地
這篇文章主要介紹了使用Node.js爬取任意網(wǎng)頁資源并輸出高質(zhì)量PDF文件到本地,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,下面小編就來和大家一起學(xué)習(xí)吧2019-06-06Node.js?中使用fetch?按JSON格式發(fā)post請求的問題解析
最近在測試一個(gè)api,可以用curl命令直接訪問,指定header相關(guān)配置,request?body(JSON),成功后返回一個(gè)JSON,這篇文章主要介紹了Node.js?中使用fetch?按JSON格式發(fā)post請求,需要的朋友可以參考下2023-04-04