egg.js部署到服務器node項目部署到服務器Egg.js

本地開發完成之後

//進入egg.js項目
cd baseDir
//安裝一下這個以來
npm install --production  或者使用 yarn add --production
//3c說的是要壓縮上傳服務器
tar -zcvf ../release.tgz .

上傳到服務器之後

框架內置了 egg-cluster 來啓動 Master 進程,Master 有足夠的穩定性,不再需要使用 pm2 等進程守護模塊。

同時,框架也提供了 egg-scripts 來支持線上環境的運行和停止。

npm i egg-scripts --save

把 npm scripts 添加到 package.json:

//照着改就行了,不要改錯
{
  "scripts": {
    "start": "egg-scripts start --daemon",
    "stop": "egg-scripts stop"
  }
}

注意:egg-scripts 對 Windows 系統的支持有限,我這裏使用的是Ubuntu服務器

啓動項目

egg-scripts start --port=7001 --daemon --title=egg-server-showcase

停止項目:修改項目都應該先停止服務,然後再修改,最後再啓動

egg-scripts stop [--title=egg-server]

參考文章https://www.w3cschool.cn/eggjslesson/eggjslesson-gu9q35yq.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章