// 引入HTTP模塊 let http = require("http") // 用http模塊創建服務 /* req 獲取URL信息 (request) res 瀏覽器返回響應信息 (response) */ http.createServer(function(req,res){ // 發送http頭部 // HTTP狀態值:200:OK // 設置HTTP頭部,狀態碼是 200.文件類型是html,字符集是utf-8 res.writeHead(200, {'Content-Type': 'text/html'}); res.write('<head><meta charset="utf-8"/></head>'); res.write("你好,nodejs") // 結束響應 res.end() }).listen(8001)