Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

ubuntu

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.

like image 861
Shuping Avatar asked Mar 29 '13 15:03

Shuping


People also ask

How do I permanently run node js server?

js application locally after closing the terminal or Application, to run the nodeJS application permanently. We use NPM modules such as forever or PM2 to ensure that a given script runs continuously. NPM is a Default Package manager for Node.


1 Answers

Many people use forever https://github.com/nodejitsu/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 https://gist.github.com/qbert65536/5271721 .

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.

like image 120
qbert65536 Avatar answered Oct 17 '22 05:10

qbert65536