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.

Installation…

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…

./configure

Make the makefile…

make

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');
}).listen(8080);
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!

5 thoughts on “How to Install Node.js on Your Server

  1. Bonjour
    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 )
    merci

  2. I have installed following your instruction but still I am getting same version like as before v0.6.12. But I am expecting v0.10.28.
    What can be the problem?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.