/**
* Created by Peter.
*/
//1.获取内嵌的http模块(提供http服务器和客户端)
var http = require('http');
//2.创建HTTP服务器
var server = http.createServer(function(req,res){
if(req.url == '/'){ //请求主页
console.log(req.getAllResponseHeaders);
res.writeHead(200,{
'Content-type':"text/html"});
res.write(''
+'床前明月光');
res.end();
}else {
res.writeHead(404,{
'Content-type':"text/html"});
res.write(''
+'错误404:网页没找到');
res.end();
}
});
//3.启动Http服务器
server.listen(3000,function(){
console.log("正在监听3000端口");
});
网友评论