With all the euphoria about node.js since the last few months, I finally decided to give it a try. As it is not available for Windows, I decided to install it on Linux instead of going for Windows/Cygwin. node.js is a implementation of CommonJS, a JavaScript ecosystem in development to be used for developing application outside the browser, like:
– Server-side JavaScript applications
– Command line tools
– Desktop GUI-based applications
Installing node.js
As mine was a clean Ubuntu installation, I needed to install certain libraries first.
sudo apt-get install g++ curl libssl-dev apache2-utils
The easiest way is to download node.js is to get a git clone. For that I needed to install the git package.
sudo apt-get install git-core
Now download node.js with git.
git clone git://github.com/ry/node.git
If you do not want to use git you could get the tar package instead.
wget http://nodejs.org/dist/node-v0.1.96.tar.gz
gunzip node-v0.1.96.tar.gz
tar -xf node-v0.1.96.tar
Now you are ready to install node.js.
cd node
./configure
make
sudo make install
Example node.js code
Below is a simple program using node.js for translating text using google API.
var http = require('http');
var url = ('ajax.googleapis.com')
var google = http.createClient(80, url);
var text = "Hello World from node!";
var requestUrl = '/ajax/services/language/translate?v=1.0&q=' +
escape(text) + '&langpair=en%7Cfr'
var request = google.request('GET', requestUrl,
{"host": "ajax.googleapis.com"});
request.end();
request.addListener('response', function (response) {
var body = '';
response.addListener('data', function (chunk) {
body += chunk;
});
response.addListener("end", function() {
var jsonData = JSON.parse(body);
console.log(jsonData.responseData.translatedText);
})
});
This simple example does not to justice to the true power of node.js. I’ll be posting useful examples in the near future. Keep watching.
simple tutorial, this is what i need..
thanks..
Thanks for this man! I will try this one…
There is a simpler way to install. nodejs deb package is availble on ubuntu repository.
just copy this single line in a terminal
sudo add-apt-repository ppa:jerome-etienne/neoip && sudo apt-get update && sudo apt-get install nodejs
http://blog.jetienne.com/2010/08/nodejs-deb-package-on-ubuntu-repository.html
Right on man, this worked for me right out of the box on my fresh ubuntu install. Thanks for sharing…
Perfect bootstrap article! Thank you. Got me started..
very nice ans simple tuts
Thank you for this great, simple tutorial!
Many thanks – well written, clear and complete.
The following site also has a useful tutorial for getting started with node.js:
http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/
Very nice. I got up and running in no time. I can’t wait to see what else you’ll publish with node.js. Thank you!
Good One… Thanks a lot
$ git clone git://github.com/ry/node.git
Cloning into node…
fatal: remote error:
Could not find Repository ry/node
Update : The node.js source files are now located at github.com/joyent/node.git
thanks to your tutorial brader.
Beside the new repo location, it’s also likely you will want a more stable version, rather than the latest. At the root of the repo, after cloning and before building:
git checkout v0.4.7
(v0.4.7 as an example)
Thanks for the straightforward and accurate instructions to get started with node.
Hi folks,
I’m so excited to taste the node… And i found this articles very useful to install the node on Ubuntu.
Keep writing great node tutorials….
Many thanks,
{Web-Farmer}
If you are installing on a bare system then you would have to install build-essential aswell.
apt-get install build-essential
I just created something similar to this article but in a small script. It can be used to update node.js at any time (compares local to remote versions).
https://gist.github.com/1410275
You can also curl the raw version and pipe it to bash, i.e.
curl -s https://raw.github.com/gist/1410275/7b44c30cca9dcadab19806d43868496f4525e20a/update-nodejs.bash | bash
if you trust the script to execute on your box.
Perfect, thanks for that 🙂
Nice artcile mate, thanks for share 😀
Very easy to implement those instruction.