If you already have them up and running, started via PM2, you can skip this step: # cd /var/www/backend/api-v1-staging/ Next, you want to start your Node.js applications using PM2 as follows. To confirm that the PM2 startup service is up and running under systemd, run the following command (replace the rvice with the actual name of your service, check the output of the previous command): # systemctl status rvice You can also explicitly specify the init system like so: # pm2 startup systems The startup sub-command tells PM2 to detect available init system, generate configuration and enable the startup system. To generate the startup script, simply run the following command as root: # pm2 startup PM2 is designed to work with the default init system on a Linux system (which it can auto-detect) to generate the startup script and configure PM2 as a service that can be restarted at system boot. Generate PM2 Start Script for Init System All commands in this article will be executed as root (use sudo where necessary for a user with privileges to invoke it). For this guide, the test system uses a systemd service and system manager.
In this article, we will show you how to deploy PM2 as a service to reliably manage your Node.js apps. When the server restarts, it will automatically restart PM2, which will then restart all the Node.js applications/processes it is managing. The start script sets up PM2 as a service under the init system. One of PM2’s key features is support for a startup script (generated dynamically based on the default init system on your server), that restarts PM2 and your processes at every server restart. Restarting PM2 with the processes it manages every time your server boots/reboots is critical.
PM2 is a powerful, widely-used, and feature-rich, production-ready process manager for Node.js.