欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

服務(wù)器端的JavaScript腳本 Node.js 使用入門

 更新時間:2012年03月07日 08:24:09   作者:  
觸爪伸向傳說中的Server-Side Javascrpt。后端JS最出名無疑是Ryan Dahl的node.js,另一個是aptana IDE提供商搞出的jaxer,這里討論node.js的使用
首先下載node.js,然后解壓到E盤,改名為node,然后開始菜單輸入cmd,用cd命令切換到nodejs的解壓目錄:

第一個例子:hello world。

在node目錄下建立hello.js文件,然后在里面輸入:
復(fù)制代碼 代碼如下:

var sys = require("sys");
sys.puts("Hello world");

然后我們在命名臺中輸入命令node hello.js,就能看到命名臺輸出結(jié)果Hello world。

第二個例子:hello world2。

好了,這次我們試從游覽器中輸出hello world。在node目錄下建立http.js,然后輸入:
復(fù)制代碼 代碼如下:

var sys = require("sys"),
http = require("http");
http.createServer(function(request, response) {
response.sendHeader(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.close();
}).listen(8080);
sys.puts("Server running at http://localhost:8080/");

然后我們在命名臺中輸入命令node http.js,在瀏覽器輸入http://localhost:8080/
第三個例子:hello world2。
node.js提供一個Buffer類用于轉(zhuǎn)換不同編碼的字符串。目前支持三種類型:'ascii','utf8'與'binary'。詳見這里
復(fù)制代碼 代碼如下:

var Buffer = require('buffer').Buffer,
buf = new Buffer(256),
len = buf.write('\u00bd + \u00bc = \u00be', 0);
console.log(len + " bytes: " + buf.toString('utf8', 0, len));

第四個例子:hello world3。
復(fù)制代碼 代碼如下:

//synopsis.js
//synopsis 摘要, 梗概,大綱
var http = require('http');

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

前臺地址欄:http://localhost:8124/

第五個例子:編譯C文件
復(fù)制代碼 代碼如下:

#include #include int main(){ printf("Hello World!!!"); exit(0); }

相關(guān)文章

最新評論