0
votes

Whenever i ran this node server on Port "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}`)
})

i get an error on the Borwser which says:

localhost didn’t send any data. ERR_EMPTY_RESPONSE

i try to change ports but still it shows this error.Please what should i do and explain me what this error is. Thank you!