Systemd Service in Nodejs

Question:

How to add systemd service for nodejs application?

Applicable to:

  • VPS Linux.
  • Dedicated Server Linux.
  • EVC Linux.

Answer:

Systemd service used to make your nodejs integration easier. Instead of run manually and hold into background process, you can make it start or stop just like another daemon apps.

In this scenario, we will put our app.js under /root and your application called server.js.

Make a file using your favourite editor vi/nano/pico:

/etc/systemd/system/exabytes-web.service

And then fill:

[Unit]
Description=Node.js Hello World Server
After=network.target

[Service]
ExecStart=/usr/bin/node /root/server.js
Restart=always
User=root
# Environment=PATH=/usr/bin:/usr/local/bin
# WorkingDirectory=/root/

[Install]
WantedBy=multi-user.target

Now reload it, enable it, and start our application as a service.

systemctl daemon-reload 
systemctl enable exabytes-web.service
systemctl start exabytes-web.service

Your nodejs application now should be running as a service.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.