http:创建http服务器的 - nodejs进行服务器开发
http模块创建服务器的步骤:
1.导入http
2.用他创建服务器
3.服务器监听端口号
const http = require('http')
创建服务器,调用它的createServer方法
要给请求做出相应,需要在createServer方法中,添加回调函数
const server = http.createServer(function(request, response){
// request - 请求报文
// response - 用来做出相应的对象
// response有一个方法end - 可以设置响应主体
response.end('this is my server,running at http://localhost:12345')
// http://localhost:12345/
})
// 监听端口号 - 服务器调用listen方法
server.listen(12345, () => {
console.log('server is running at http://localhost:12345');
})