第二节 Node.js实现hello,world
1.新建文件helloword.js
2.编码如下:
var http = require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type': 'text/html; charset=utf-8'});
if(request.url!=="/favicon.ico"){ //清除第2此访问
console.log('访问');
response.write('hello,world');
response.end('hell,世界');//不写则没有http协议尾,但写了会产生两次访问
}
}
).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
3.运行及访问:
启动服务 cmd下执行:

node helloword.js
浏览器访问:http://localhost:8000


勇者无惧,强者无敌。


浙公网安备 33010602011771号