I recently installed Ubuntu 9.10 on VMWare 6.5 Workstation and wanted to try out Node.js. According to the Node.js website Node is a way to provide an easy way to build scalable network programs. The nice thing about Node is that it is event driven (making use of Javascript’s strength with events and also making it easy to learn) and there are no “locks”. Node is similar to Ruby EventMachine or Python Twisted. There is already a strong user community here.
Lets go ahead a build a couple simple apps using Node.js. I’ll assume from here that you already have Ubuntu 9.10 already running.
On a clean install of Ubuntu 9.10 I quickly found out that git was not installed by default. You can fix that by going to the terminal and running this command (you’ll probably need to use “sudo” before the commands):
apt-get update apt-get install git-core apt-get install build-essential
Once GIT is install you can then clone the Node.js repository:
git clone git://github.com/joyent/node.git
Move into the new “node” directory:
cd node
Now configure and install:
./configure make sudo make install
This should work flawless (at least it did for me).
At this point you can take the demo from the Node.js homepage and copy or type in the code. I’ve taken the demo code and slightly modified it.
var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
setTimeout(function () {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<br/><strong> Hello World!</strong>');
res.end();
}, 2000);
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
I named my file “sayhello.js”. Now you can run the code like this:
Fire up your browser to this address and you should see the result.
At this point you can start looking into some examples here. You can also play with the API as well.
In this next example I’m simply dumping out the HTTP Request object to inspect it. The code used for this is in line #8.
var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
setTimeout(function () {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<br/><strong> Hello World!</strong>');
res.end();
sys.puts(sys.inspect(req, false));
}, 2000);
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
If you look through the documentation you will also see that Node.js has support to be a TCP server, which means if you are a Silverlight or Flash/Flex developer you can use Node.js to build a socket server.
Enjoy working with Node.js!








Pingback: Trying out WebSocket with Node.js and Google Chrome in Ubuntu 9.10 « Giant Flying Saucer
Pingback: Building a socket server with Node.js and Flash CS4 « Giant Flying Saucer
Pingback: Messing around with Node.js and HTTP « Giant Flying Saucer
Pingback: Getting started using Node.js and Express.js to build a simple website « Giant Flying Saucer
Well good examples.. however I had a problem building node on my karmic koala with your method.. I solved it however by first downloading the tar.gz node source from nodejs.org installing the required dependencies (openssl and g++) before i run the examples you provided.. i’m definitely going to investigate further.. l8r
You should tell people to run apt-get install build-essential
too, first to get the compilers and so forth installed.
@Doug,
Good point. I’ll update the article.
Chad
Pingback: Building a socket server with Node.js and Flash CS4 | Giant Flying Saucer
Pingback: Installing Node.js and NPM on Ubuntu 10.04 and try a simple chat application « Giant Flying Saucer
I followed these steps and it worked on 9.04 – except I had to do a couple of extra steps.
when I tried to ./configure, it said that there were libssl packages missing. I then tried to make and it gave an error.
I installed libssl-dev and lib0.9.8 in the synaptic package manager and it worked fine.
Also, in my case, I had to apt-get install pkg-config to get a green light on the ./configure’s answer for openssl
for openssl you need add:
sudo apt-get install libssl-dev
Worked just like a charm… Thanks.
Pingback: Installing Node.js and NPM on Ubuntu 10.04 and try a simple chat application | Giant Flying Saucer
Hi,
First up, thanks for the nice article.
Small update though:
git clone git://github.com/ry/node.gitThat url didn’t work . I used git clone
git://github.com/joyent/node.gitand it worked as expected.@Sridhar,
Thanks, yes they recently moved where NodeJS was hosted on GitHub.
I’ve updated the article now.
Chad
just wanted to say what a great post. I followed all the steps on OSX 10.6 and the only problem I ran into was that it doesn’t work if MAMP (I think LAMP on Linux) is running at the same time. It will tell you that the server is running in Terminal, but won’t work in the browser. I turned MAMP off and it was fine.
Thanks again
Pingback: Install and try Node.js | Everything stepwise
If you show up as a result of the documentation you are maybe to also see that Node.js has assist obtaining a TCP server, which signifies if you arrive going to really are a Silverlight or Flash/Flex builder you are gonna be while in the place to use Node.js to produce a socket server.
Thanks for the recipe – worked for me on rackspace cloud
The timeout in the sayhello.js script introduces a delay which might disappoint people who are eager to see a nice quick response. This worked for me too:
var sys = require(‘sys’),
http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/html’});
res.write(‘ Hello World!‘);
res.end();
}).listen(8000);
sys.puts(‘Server running at http://127.0.0.1:8000/‘);