今天给你们讲解Node Http服务,发送服务器请求以及监听请求前端
app.js中引入http模块bash
const http = require('http')
复制代码
建立http服务器,这里以本地为例服务器
// 建立本地服务器
const sev = http.createServer(function (req,res) {
console.log(req.url + '向服务器发送了请求')
res.writeHead(200,{'Content-type': 'text/plain'})
res.end('true')
})
复制代码
监听请求app
// 监听请求
sev.listen(8088,'localhost')
复制代码
但愿个人分享对你有所帮助,更多资讯请持续关注,我会分享愈来愈多的实战经验哦! 或加入大前端知识体系社区一块儿探索技术:608229520ui