linux 下開啟一個簡單的web服務:
首先需要linux下安裝nodejs
然后創建一個test.js: vi test.js
var http =require("http"); function hello(req,res){ res.writeHead(200,{"content-type":"text/plain"}); res.end("hello, word"); } http.createServer(hello).listen(12306,"192.168.0.108"); console.log("hello, word");
保存退出后執行:node test,js
客戶端打開瀏覽器輸入:192.168.0.108:12306 即可看到瀏覽器輸出結果:
hello, word