0

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.

VISHAL
  • 1
  • 1
  • 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 Answers2

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
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.

https://pm2.keymetrics.io/

With this you can run in background

K1games
  • 131
  • 3