认识 http
通过 http.createServer(callback)
创建一个http服务,通过 listen(port, callback)
监听端口。
const http = require('http')
let app = http.createServer((req, res) => {
console.log(req.url) // 打印 url
res.write('hello world') // response写入
res.end() // 结束写入,与 write 函数结合使用
})
app.listen(8080, () => {
console.log('listen on 8080 port...')
})
解析get请求
queryString
库的使用url
库的使用
解析 post 请求
Buffer
的使用app.on('data', callback)
和app.end(callback)
的使用