I thought I would put this together quickly because in typical Linux fashion something that should be straightforward isn’t… Node.js – I am still not sure what it is :), however I am in the process of setting up drupalchat on one of my sites and when I tried using it with the AJAX option, which worked well for a couple of users, it made the site run extremely slowly. The server has plenty of grunt… dedicated Ubuntu 13 VM running 3 cores and 2 GB of RAM and this particular site was the only thing running on it. Furthermore, the MySQL database server was/is on a separate dedicated VM… so there is no way it was a lack of firepower. DrupalChat running with AJAX was causing problems. I am going to launch a fuller tutorial on getting drupal chat setup but I figured I would do the node.js thing here and now….

So without further ado… Login to your box and elevate your privileges to root, then install the app via the package manager…

sudo -s
apt-get update
apt-get install nodejs

But you aren’t done yet… if you tried to test right now via the “node blabah.js” command ubuntu would say it doesn’t have a clue what the Node command is. That is because, for whatever odd and unknown reason, the person that put the apt package together used a different name for the command than what everyone else uses. So, an easy fix is to create a symlink from “node” to the command they went with. That way all your other nodejs stuff that expects the “node” command will work. Run this command:

ln -s `which nodejs` /usr/local/bin/node

Finally, we are going to create a quick script that will let your test your node.js installation…

cd ~
vim hello_node.js

That creates a new blank file and opens it up in the VIM text editor. Copy the following code into your new file. Update the IP address shown ( to the IP address on one of your servers network cards (you can check that with “ifconfig” command). The IP is in two places. Update it in both. The second instance of it is just the log that gets output to the console after you excecute this file but it is good to be accurate/consistent.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(8124, "");
console.log('Server running at');

Save and close your file.

Now run the following command:

node hello_node.js

and you should get this output:

Server running at http://whatever.IP.address.you.entered:8124

Now from a web browser, in the URL bar type (this assume the machine running the web browser has access to that IP address and port):


And you should see “Hello World!” which means that your application is running and Node.JS is installed correctly!


1 of 1

This post has no comments. Be the first to leave one!

Join the discussion

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