How to auto start PM2 with Node Application on Windows after reboot?

Today I gonna share with you guys how to auto start PM2 with Node Application on Windows after reboot? For this approach, we will use this pm2-windows-service module to achieve this.

1. Configure the PM2

npm i -g pm2
  • Copy C:\Users\<Windows-Username>\.pm2 folder to C:\etc\.pm2
  • Add a new system variable name: PM2_HOME and value: c:\etc\.pm2

2. Start and Save your new node application with PM2

pm2 start server.js --name server 
pm2 save

3. Install the PM2 windows service

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

4. Set the following parameters

– Perform environment setup (recommended)? Y
– Set PM2_HOME? Y
– PM2_HOME value (this path should be accessible to the service user and
should not contain any “user-context” variables [e.g. %APPDATA%]): c:\etc\.pm2\
– Set PM2_SERVICE_SCRIPTS (the list of start-up scripts for pm2)? N
– Set PM2_SERVICE_PM2_DIR (the location of the global pm2 to use with the service)? [recommended] Y
– Specify the directory containing the pm2 version to be used by the
service C:\USERS\\APPDATA\ROAMING\NPM\node_modules\pm2\index.js Press Enter

PM2 service installed and started.

That’s it. I hope this will help. 🙂
Photo: https://www.brandeps.com

Leave a Reply

Your email address will not be published. Required fields are marked *