liea

Node创建web服务器

示例代码:

 1 // 请用系统模块
 2 const http = require(\'http\')
 3 // 创建Web服务器
 4 const app = http.createServer()
 5 // 当客户端发送请求的时候
 6 app.on(\'request\', (req, res) => {
 7   // 响应
 8   res.end(\'hello word\')
 9 })
10 // 监听3000端口
11 app.listen(3000)
12 console.log(\'服务器启动成功,监听端口:3000\')

 打开方式: 浏览器输入 localhost:3000

 

分类:

技术点:

相关文章:

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