var http = require('http');//node.js自带http服务
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'});
if(req.url != '/favicon.ico'){//清除掉,防止第二次访问
console.log("访问");
res.write("hello world");
res.end('');//结束请求,不写则没有结束
}
}).listen(8090);//端口
console.log('服务器已启动... http://localhost:8090/');
运行结果:
浏览器打开地址: