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
原文地址:https://www.cnblogs.com/Anderson-An/p/10124554.html