Create http server module of static

Create http server module of static

const http=require('http');
const server=http.createServer();
server.on('request',function (req,res) {
    console.log("收到用户请求")
    // res.setHeader('Content-Type', 'text/html;charset=utf-8');处理乱码
    res.setHeader('Content-Type', 'application/json');
    res.write("你好啊世界")
    res.end()
  })
  server.listen(8880,function () {
      console.log('服务器启动成功')
    })

Guess you like

Origin www.cnblogs.com/hff-syt/p/12165459.html