Hope Have Good tech
Linux extend php apache server mvc java

note: I copy below example from internet.

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.

posted on 2010-12-23 21:06  JackeyChan  阅读(221)  评论(0)    收藏  举报