node中创建服务器可以分为以下4个步骤
1.我们需要引入对应模块
// 引入http模块
const http = require('http')
2.创建web实例:
// 创建web服务器实例
const server = http.createServer()
3. 为web服务器绑定request事件 响应客户端的请求:
server.on('request', function(req, res) {
console.log('当前处于服务器中');
})
4.启动服务器:
//80 为端口号
server.listen(80, function() {
console.log('服务器运行中 地址 http://127.0.0.1:80');
})