Install and Setup Node.js to Run Forever

Install and Setup Node.js to Run Forever


This article is pretty old and was never very good to start with. A much better solution is Deploying Node.js With Upstart and Monit

Install Node.js

$ sudo apt-get update
$ sudo apt-get install git-core curl build-essential openssl libssl-dev
$ git clone && cd node

I had trouble using the latest (head) verson of node so I used an older version which is optional.

git checkout origin/v0.4

If you don't want the older version, skip the previous command.

$ ./configure
$ make
$ sudo make install
$ node -v

Install Node Package Manager (NPM)

$ curl | sudo sh
$ npm -v

Install Forever

Next, lets make it persistent using Forever, so once we logoff it still runs and will restart even if node throws an error.

sudo npm install forever --global


Make a Test Script

Create a file called test.js and paste this into it.

var util = require('util'),
http = require('http');

http.createServer(function (req, res) {
   res.writeHead(200, {'Content-Type': 'text/plain'});
   res.write('hello, i know nodejitsu.')
/* server started */
util.puts('hello world running on port 8000');

Run it Forever (until you kill it)

forever start test.js

You should be able to see it here

ps axl | grep node

And here

forever list

You can kill it using

forever stop 0

Where 0 is the index of your code in the forever list.

Time to start javascripting.


Installing Node Wiki

Installing Node.js and NPM on Ubuntu 11.04

Keep A Node.js Server Up with Forever