文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Example of node.js 1

Example of node.js 1

时间:2010-12-23  来源:JackeyChan

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.

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载