Windows: Auto start PM2 and node apps

前端 未结 3 1137
礼貌的吻别
礼貌的吻别 2021-01-30 18:40

At a Windows AWS server i have a NODE app and i\'m using PM2 to launch the app

I have tried the NPMs: \"pm2-windows-startup\" and \"pm2-windows-service\"

But aft

3条回答
  •  被撕碎了的回忆
    2021-01-30 19:07

    I found this tutorial very useful: https://blog.cloudboost.io/nodejs-pm2-startup-on-windows-db0906328d75

    the first approach using 'nssm' and a .bat file not worked for me, so I followed approach 2: "Solution2: Using pm2-windows-service"

    However, as mentioned in other answers, the pm2-windows-service has a bug, which this fork solved: https://www.npmjs.com/package/@innomizetech/pm2-windows-service

    so instead of the old package:

    npm install -g pm2-windows-service

    use the new one:

    npm install -g @innomizetech/pm2-windows-service

    here a short summary of the tutorial:

    Configure pm2

    1. npm i -g pm2
    2. copy C:\Users\USER\.pm2 to C:\etc\.pm2
    3. set a new System Variable (not user level) name: PM2_HOME value: c:\etc\.pm2

    Runnning your app with pm2

    1. run your pm2 app. ie: pm2 start app.js --name=MY_API .
    2. pm2 save to create a dump of the current apps running.

    Testing app

    1. to test everything is working, try: pm2 kill and then pm2 resurrect (app should be running, check with pm2 status )

    Run at startup

    now we need to perform the resurrect command at startup, so:

    1. npm install -g @innomizetech/pm2-windows-service
    2. pm2-service-install -n PM2 --unattended

    thats it.

提交回复
热议问题