티스토리 뷰

etc

install node.js

Sumin Lim 2012. 1. 25. 18:48
반응형

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.

반응형

'etc' 카테고리의 다른 글

VendingMachine  (0) 2012.03.25
js url encode  (0) 2012.02.07
nginx  (0) 2012.01.11
css  (0) 2012.01.11
<고독의 위로] 앤서니 스토  (0) 2011.11.21
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함