linux系統下開啟一個簡單的web服務


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM