创建web服务器

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

原文地址:https://www.cnblogs.com/liea/p/11218629.html