app.on 为服务器添加事件
res.end(里面的内容就是要相应的内容)
// 创建web服务器
// 引用系统模块
const http = require('http');
// 创建web服务器
const app = http.createServer();
// 当客户端发送请求的时候
app.on('request', (req, res) => {
// 获取请求方式
// req.method
console.log(req.method);
console.log(req.url);
// req.url 获取请求地址
// req.headers 获取请求报文
// 响应
res.end('<h1>hi</h1>');
});
// 监听3000端口
app.listen(3000);
console.log('服务器已启动,监听3000端口,请访问localhost:3000')
// 用node 命令执行这个文件