Node.js学习第二课http请求

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/');

运行结果:

浏览器打开地址:

猜你喜欢

转载自blog.csdn.net/dhj199181/article/details/81428902