Automatically Start Node.js Server When System Reboots. Installing and Using the PM2 Module on Linux

You can use the pm2 module to make the application start automatically when the system boots up or restart if the application crashes. It automatically restarts the application (if it crashes or is killed) so that the server is always available.

1) PM2 Installation

A) “npm install -g pm2” for Windows, “sudo npm install pm2 -g” for Linux
B) We can use the “npm list -g” command to see that the installation is completed globally.

2) Starting our App with PM2

First, let’s list the currently running applications with the “pm2 list” command. There is no running application as in the picture above.

To start the app with pm2 “pm2 start ‘our own app launcher'”

3) Auto-start when the system restarts

A) Let’s execute the instruction on the screen once with the “pm2 startup” command.

B) In order for the applications to restart, we must save the open applications with “pm2 save”.

C) Let’s write the command “pm2 startup” again so that the saved applications will start.

Our application in our port is still running.

4) Latest situation

a) We reboot system

b) We check whether it is open with the “pm2 list” command. As you can see it started automatically.

5) List connected applications and get information

pm2 list
pm2 info 2

6) Update command

“pm2 update”

7) Application monitoring screen

“pm2 monit”

8) Saving the latest status of the application list

“pm2 save”
“pm2 save –force”

9) Resurrect last saved

“pm2 resurrect”

19) Stop open applications

“pm2 kill”

Bir Cevap Yazın

This site uses Akismet to reduce spam. Learn how your comment data is processed.