nodejs 初探
2017-7-20,于簡書 http://www.lxweimin.com/p/8e20037e0434
新建一個 index.js
文件,然后寫入如下代碼:
var http = require("http");
http.createServer(function (request, response) {
// 發送 HTTP 頭部
// HTTP 狀態值: 200 : OK
// 內容類型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 發送響應數據 "Hello just do IT"
response.end('Hello just do IT');
}).listen(8888);
// 終端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
在控制臺中運行 node index.js
,會輸出 Server running at http://127.0.0.1:8888/
,然后在瀏覽器打開 http://127.0.0.1:8888
。
參考:
今日歌曲推薦:La La Land