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