Questions And Answers

More Tutorials

NodeJS Running as a service

Node.js as a systemd dæmon

systemd is the de facto init system in most Linux distributions. After Node has been configured to run with systemd, it's possible to use the service command to manage it.

First of all, it needs a config file, let's create it. For Debian based distros, it will be in /etc/systemd/system/node.service
Description=My super nodejs app
# set the working directory to have consistent relative paths
# start the server file (file is relative to WorkingDirectory here)
ExecStart=/usr/bin/node serverCluster.js
# if process crashes, always try to restart
# let 500ms between the crash and the restart
# send log tot syslog here (it doesn't compete with other log config in the app itself)
# nodejs process name in syslog
# user and group starting the app
# set the environement (dev, prod…)
# start node at multi user system level (= sysVinit runlevel 3)

It's now possible to respectively start, stop and restart the app with:

service node start
service node stop
service node restart

To tell systemd to automatically start node on boot, just type: systemctl enable node.

That's all, node now runs as a dæmon.


In this page (written and validated by ) you learned about NodeJS Running as a service . What's Next? If you are interested in completing NodeJS tutorial, your next topic will be learning about: NodeJS with CORS.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.