1. 程式人生 > >Node.js起一個web服務器

Node.js起一個web服務器

ont pla req esp alt 服務 func color ron

技術分享

開啟服務:

技術分享

代碼如下:

var http = require(http);

http.createServer(function (request, response) {

    // 發送 HTTP 頭部 
    // HTTP 狀態值: 200 : OK
    // 內容類型: text/plain
    response.writeHead(200, {Content-Type: text/plain});

    // 發送響應數據 "Hello World"
    response.end(Hello World\n);
}).listen(8888);

// 終端打印如下信息
console.log(Server running at http://127.0.0.1:8888/);

Node.js起一個web服務器