티스토리 뷰
반응형
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
링크
TAG
- LECTURE
- pytorch
- ML
- Neo4j
- Paper
- amazon
- 통계
- Shell
- LeetCode
- mongodb
- tag hello
- 알고리즘
- 기본
- nvidia #gan
- geometry
- 자바
- quiz
- MachineLearning
- 파이썬
- linkedin-skill-assessments-quizzes
- extract archive multiple files
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함