var http = require('http'); //引入内置模块http模块
//2
http.createServer(function(request, response){
response.writeHead(200, { 'Content-Type': 'text-plain' });
response.end('Hello World\n');
}).listen(8080);
- var http = require('http'); //引入内置模块http模块
- http.createServer (function{}); //创建服务器
- response.writeHead() //响应头
- response.end() //表示的就是响应事件传输数据结束
http.createServer(function(request,response){}).listen(8080);
这就是创建一个服务器,监听服务器上8080端口
用nodejs运行此文件,浏览器访问 localhost:8080, 就会显示服务器响应信息