process - How do I run a node.js app as a background service? - Stack Overflow

PHOTO EMBED

Sun Oct 22 2023 03:56:47 GMT+0000 (Coordinated Universal Time)

Saved by @StephenThevar #javascript

[Unit]
Description=My app

[Service]
ExecStart=/var/www/myapp/app.js
Restart=always
User=nobody
# Note Debian/Ubuntu uses 'nogroup', RHEL/Fedora uses 'nobody'
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/myapp

[Install]
WantedBy=multi-user.target
content_copyCOPY

PM2 alternative. This is when node is deployed into prod and for daemonising.

https://stackoverflow.com/questions/4018154/how-do-i-run-a-node-js-app-as-a-background-service