1.加载http模块
var http=require('http')
2.创建http服务对象
var server=http.createServer()
3.监听request请求事件
server.on('request',function(req,res){
//响应开始
res.write('hello world');
//响应结束
res.end();
}
);
4.启动服务
server.listen(8080,function(){
console.log('服务器启动了,请访问http://localhost:8080');
}
)
http Content-Type 对照表
req.url 返回的url只是一个标识,具体返回什么取决服务器
res.end(data);