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