When I restart the ubuntu server the node.js services in the server are not running in the background. I need to connect to the server and start the services whenever I restart the server.
Asked
Active
Viewed 1,197 times
0
-
Does this answer your question? [How do I run a node.js app as a background service?](https://stackoverflow.com/questions/4018154/how-do-i-run-a-node-js-app-as-a-background-service) – mikemaccana Mar 17 '22 at 09:40
-
Enable the service to autostart? What are you using to handle your node process, systemd? -> `systemctl enable
` – Marc Mar 17 '22 at 20:07
2 Answers
1
Use PM2.
To install PM2:
npm install -g pm2
To start a node.js process:
pm2 start -n "My task name" /path/to/node/script
To list process:
pm2 list
To restart manually a process (after update for example):
pm2 restart <id of process>
PM2 will handle restart automatically in some case, or you can also tell PM2 to restart node process if script change. And many other cool things.

Alaindeseine
- 3,260
- 1
- 11
- 21
-
You can also save your pM2 configuration with ``pm2 save`` and restore with ``pm2 resurect`` – Alaindeseine Mar 17 '22 at 09:56
0
You need to use pm2 is a advanced process manager for production Node.js applications. Load balancer, logs facility, startup script, micro service management, at a glance.
With this you can run in background

K1games
- 131
- 3