windows系統(tǒng)下自啟動
方案一:使用PM2自啟動 文章:https://pm2.io/doc/en/runtime/guide/startup-hook/
https://github.com/marklagendijk/node-pm2-windows-startup
安裝 (前置條件全局安裝了pm2 也即是 cnpm i -g pm2)
cnpm install pm2-windows-startup -g
pm2-startup install
--前置條件先到項目目錄 npm run production啟動
pm2 save
卸載
pm2-startup uninstall
This removes the registry entry that starts the process on startup
方案二:使用nssm 安裝成服務(wù)
首先準(zhǔn)備一個startup.bat
bat文件內(nèi)容: 如果服務(wù)器支持pm2 npm run production
如果不支持 npm run dev
nssm下載地址:http://www.nssm.cc/download
下載最新日期的 解壓到一個目錄迷扇,進(jìn)入win64目錄双揪,打開命令行
nssm install bimservice
此時會彈出一個窗口锄贷,定位并選擇上面的bat文件 安裝即可
注意:現(xiàn)在雖然服務(wù)已經(jīng)安裝好了翩迈,但是并沒有啟動俺孙,需要打開 services.msc, 找到bimservice 啟動起來
因為這個服務(wù)是自啟動的伟葫,所以下次重啟電腦鼓蜒,服務(wù)會自動開啟家乘。
卸載服務(wù)
首先方仿,先把服務(wù)停止固棚,接著進(jìn)入nssm的 win64目錄
打開命令行
nssm remove bimservice
package.json
{
"name": "koa2-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon -w src src/app.js",
"production": "pm2 start process.json",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"kcors": "^2.2.1",
"koa": "^2.5.0",
"koa-bodyparser": "^4.2.0",
"koa-json": "^2.0.2",
"koa-logger": "^3.2.0",
"koa-router": "^7.4.0",
"log4js": "^2.5.3",
"md5": "^2.2.1",
"pg": "^7.4.1",
"request": "^2.85.0",
"uuid": "^3.3.2",
"ws": "^5.2.0"
},
"devDependencies": {
"nodemon": "^1.17.5"
}
}
pm2的配置信息,process.json
{
"apps" : [{
"name" : "0easyDS",
"script" : "./src/app.js",
"instances" : "max",
"exec_mode" : "cluster",
"env": {
"NODE_ENV": "development"
},
"env_production" : {
"NODE_ENV": "production"
}
}]
}