Localhost is suddenly unreachable?

mongodb, is used in node and listens to the service on the local port, which has been accessible normally until now, but has suddenly been inaccessible. Can"t find out what the problem is

// connect mongoose
mongoose.connect("mongodb://localhost/coursedesign")
    .then(() => {
        console.log("mongodb is connecting...");
    })
    .catch(err => {
        console.log(err);
    })
// 
var port = 5000;
app.listen(port,() => {
    console.log(`Server running on ${port}`);
})

Terminal displays normal startup

clipboard.png
localhost

clipboard.png
what went wrong? Solve

Aug.07,2021

check the firewall to see if your port 5000 is closed


  1. check to see if the MongoDB service is started;
  2. if the MongoDB service is started, check to see if the port is correct.

from the point of view of the error, "localhost did not send any data" means that the problem is still on your server side, not the firewall.
logically, if "mongodb is connecting" appears, the MongoDB is connected. So it's not MongoDB's problem.
I think the problem may be your Express configuration. How do you define your router? There must be code in the corresponding router for how to respond to the request. Similar to:

app.get('/', function(req, res){
  res.send('hello world');
});

such processing code.

Menu