On App Hosting the panel keeps your app running for you. On a VPS or dedicated server you need a process manager. PM2 restarts the app if it stops, starts it again after a server reboot and keeps its logs.
-
Install PM2
npm install -g pm2 -
Start the app
Go to the app folder, install its dependencies and start it with a name:
cd /home/my-app npm install pm2 start index.js --name my-app -
Start it automatically after a reboot
pm2 startupThe command prints a line that starts with
sudo env PATH=.... Copy it and run it. Then save the list of running apps:pm2 save -
Check it
pm2 statusThe app should be listed as
online.
Useful commands
| Command | What it does |
|---|---|
pm2 logs my-app | Shows the logs live |
pm2 restart my-app | Restarts the app, for example after an update |
pm2 stop my-app | Stops the app |
pm2 delete my-app | Removes it from PM2 |
pm2 monit | Shows CPU and memory use |