【发布时间】:2022-02-02 02:22:37
【问题描述】:
每当我在端口“8000”上运行此节点服务器时
const http=require('https')
const PORT=8000
const server=http.createServer()
server.on('request',(req,res)=>{
if (req.url==='friend'){
res.writeHead(200,{
'Content-Type':'text/plain',
})
res.end(JSON.stringify({
id:1,
name:'Sir Issac Newton',
}))
}
if (req.url==='foe'){
res.writeHead(200,{
'Content-Type':'text/plain',
})
res.end('The Enemy is Ego Bro')
}
})
server.listen(PORT,()=>{
console.log(`the respnse is exectued at ${PORT}`)
})
我在 Borwser 上收到一条错误消息:
localhost 没有发送任何数据。 ERR_EMPTY_RESPONSE
我尝试更改端口,但仍然显示此错误。请问我应该怎么做并解释这个错误是什么。谢谢!
【问题讨论】:
标签: javascript node.js web localhost node-modules