How to make a ‘service’ running my Node.js application on Ubuntu server

How to make a ‘service’ running my Node.js application on Ubuntu server


I don’t know what I should call it on Ubuntu Server, but most time I work on Windows it is called a service for running an application on the background.

I build my web server based on Node.js, so to deploy it on Ubuntu sever I need a ‘service’ for running Node.js, I want the ‘service’:

  1. Running on the background
  2. Has the ability to start Node.js automatically if my web server crashes Node.js

Normally, I run a Node.js application by opening a terminal an run the js file. But from my understanding this is more for testing purpose because there is no guarantee from the terminal to start Node.js after a fail.

Problem courtesy of: Shuping


Many people use forever , which has become pretty much industry standard.

If you are on Ubuntu, you can also use init scripts ( google ‘ubuntu upstart’ ), that will do much the same thing, and are guaranteed to if the server ever gets restarted.

Here is my upstart script for example .

It gets run when the server starts, you also control them with

start myapp, stop myapp, restart myapp , where myapp.conf is the name of the upstart script.

Solution courtesy of: qbert65536


Leave a Reply

Your email address will not be published. Required fields are marked *