// 引入HTTP模块
let http = require("http")

// 用http模块创建服务
/*
 req 获取URL信息 (request)
 res 浏览器返回响应信息 (response)
*/
http.createServer(function(req,res){
    // 发送http头部
    // HTTP状态值:200:OK
    // 设置HTTP头部,状态码是 200.文件类型是html,字符集是utf-8
    res.writeHead(200, {'Content-Type': 'text/html'});  
    res.write('<head><meta charset="utf-8"/></head>'); 
    res.write("你好,nodejs")
    // 结束响应
    res.end()
}).listen(8001)

 

相关文章:

  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-12-03
  • 2021-12-08
  • 2021-11-23
  • 2021-11-28
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2021-07-28
  • 2021-10-09
相关资源
相似解决方案