nodejs之简单应用

1、nodejs第一个应用,入口函数为http.createServer()

var http=require('http');//1.引入 http 模块

//2.用 http 模块创建服务
http.createServer(function(req,res){
  // 发送 HTTP 头部
  // HTTP 状态值: 200 : OK
  //设置 HTTP 头部,状态码是 200,文件类型是 html,字符集是 utf-8
  res.writeHead(200,{"Content-Type":"text/html;charset='utf-8'"});
  res.write('你好 nodejs');
  res.write('我是第一个 nodejs 程序');
  res.end(); /*结束响应*/
}).listen(8001);

猜你喜欢

转载自www.cnblogs.com/ywjfx/p/10396982.html