16 Apr

How to Install Node.js on Your Server

Posted by Mike Categories: Blog
How to Install Node.js on Your Server

A quick guide for getting up and running with node js on your personal server.

Getting started…

If you don’t already have git installed on your server I suggest you refer to my earlier post on installation. We’ll be using git to grab node.js in this tutorial. You also must have root or shell exec access in order to execute an installation, if you don’t have ssh or command line access to your server, check with your hosting provider.


Change to your temporary directory…

cd /var/tmp

Tell git to grab the latest installation of node js…

git clone git://github.com/joyent/node.git

Now change to the new directory of node…

cd node

Configure the installation…


Make the makefile…


Install node…

make install

Double check node was installed correctly by typing this command…

node --version

If everything was set up correctly you should get a return in the command line with the latest version of node installed on your server.

Running the server…

Now that you have node installed, let’s get a quick hello world up so we can make sure everything is configured properly and start experiementing with node!

Let’s assume you want to run a server available from http://yourdomain.com/. Change to your domain’s home directory…

cd /home/mydomain/public_html

Now create a file in here that will be our node server. When run from the command line, this file will tell node to listen on whatever port you designate. When it gets a hit, it will send an output that we specify.

Create a file named node_test.js…

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World!\n');
console.log('Server running at http://mydomain.com:8080/');

Save this file in your domain’s directory.

Then run it in the command line…

node /home/mydomain/public_html/node_test.js

You can also set the process to run indefinetely on your server by running the command with an “&” symbol at the end…

node /home/mydomain/public_html/node_test.js&

You should get a response that looks like this…

In your browser type in “http://yourdomain.com:8080/” and you should see the response from node that we entered in above! If everything is configured properly, your node process should be running in the command line and listening on port 8080 for any connections, when it gets hit, it will output our message!

One Comment on “ How to Install Node.js on Your Server ”

  1. florient April 13, 2012 at 2:15 PM

    je veux savoir comment installer node sur le serveur ,sachant que j’ai un projet sur un serveur , et je veux bien faire communiquer les fichiers .js entre eux . pour cela j’ai copier le dossier nodejs contenant node package manager, dans mon projet.
    ma question :
    comment mes fichiers .js accederons au modules nodejs (npm) .est ce qu’il faut configurer des classPath ou un truc dans le genre (je travail avec eclipse )

Leave a Reply
  1. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>