First, load the http core module
const http = require('http')
Second, use the http.createServer () method to create a Web server and return a Server instance
const server = http.createServer()
3. Turn on the server and respond
server.on('request', (req,res)=> {
//req获取更多信息
//res.end做出响应
res.end('<p>hello</p>')
})
Four, bind port number 3000, start the server
server.listen(3000);
console.log('服务器启动成功了,可以通过 http://127.0.0.1:3000/ 或localhost:3000来进行访问')
req.headers
Get request message, egreq.headers['键名']
req.url
Get addressreq.method
Request method