Local Host didnt send any data :ERR_EMPTY_RESPONSE ,either express not working or chrome

Viewed 2944

Here is my code:

const express= require('express');

var app=express();


app.get('/',(req,res)=>{
    console.log('Sending data');
    res.send('Hello Express!');
    console.log('Data sent');
});

const port = process.env.port || 8080;

app.listen(port,()=>{
    console.log('Listening to port ',port);
});

Operating system is Windows 10 and node version is 10.11.0 and express version is 4.14.0 Code Editor is VS Code

On running the localhost:8080/,the prompt is showing:

Listening to port 8080 Sending data Data sent Sending data Data sent Sending data Data sent

and then the page shows: This page isn’t working localhost didn’t send any data. ERR_EMPTY_RESPONSE

I have tried port 3000 and still same error.I have also tried Internet Explorer. I think either express not sending data or browser is unable to receive.

1 Answers

Probably process.env.PORT is not defined on your machine and its returning undefined then its trying to listen on 8080 which is already occupied. Please try 4000 or something higher than this it will work.

Related