今天給你們講解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