// 表示引入http模塊
var http = require('http');
// 接收兩個參數,一個是request和response
// request 獲取url傳過來的信息
// response 給瀏覽器響應信息
http.createServer(function (request, response) {
// 設置響應頭
response.writeHead(200, {'Content-Type': 'text/plain'});
// 頁面上輸出一句話,並且結束響應
response.end('Hello World');
}).listen(8081);端口
console.log('Server running at http://127.0.0.1:8081/');
在瀏覽器中輸入 http://127.0.0.1:8081/
顯示