Node.js Mongo未处理的错误EADDRINUSE ::: 5000

时间:2019-01-20 16:21:22

标签: node.js reactjs

我可能从我的MERN应用程序的后端收到此错误,我不知道如何处理该错误以及该错误的确切含义:

events.js:167
[0]       throw er; // Unhandled 'error' event
[0]       ^
[0]
[0] Error: listen EADDRINUSE :::5000
[0]     at Server.setupListenHandle [as _listen2] (net.js:1336:14)
[0]     at listenInCluster (net.js:1384:12)
[0]     at Server.listen (net.js:1471:7)
[0]     at Function.listen (/Users/robertosannazzaro/Desktop/Coding/crud_fabrizio/node_modules/express/lib/application.js:618:24)
[0]     at MongoClient.connect (/Users/robertosannazzaro/Desktop/Coding/crud_fabrizio/server.js:19:9)
[0]     at result (/Users/robertosannazzaro/Desktop/Coding/crud_fabrizio/node_modules/mongodb/lib/utils.js:414:17)
[0]     at executeCallback (/Users/robertosannazzaro/Desktop/Coding/crud_fabrizio/node_modules/mongodb/lib/utils.js:406:9)
[0]     at err (/Users/robertosannazzaro/Desktop/Coding/crud_fabrizio/node_modules/mongodb/lib/operations/mongo_client_ops.js:286:5)

[0]     at connectCallback (/Users/robertosannazzaro/Desktop/Coding/crud_fabrizio/node_modules/mongodb/lib/operations/mongo_client_ops.js:241:5)
[0]     at process.nextTick (/Users/robertosannazzaro/Desktop/Coding/crud_fabrizio/node_modules/mongodb/lib/operations/mongo_client_ops.js:463:7)
[0] Emitted 'error' event at:
[0]     at emitErrorNT (net.js:1363:8)
[0]     at process._tickCallback (internal/process/next_tick.js:63:19)

我做错了什么,如何摆脱呢?仅在刷新我的应用程序之后,并且当我在前端执行GET请求到后端时,此错误才会始终发生。 我试图通过执行以下操作来捕获frondend中的任何错误:

componentDidMount() {
  setInterval(() => {
    this.setState({
      curTime: new Date().toLocaleString()
    });
  }, 1000);
  axios.get("http://localhost:5000/").then((res, err) => {
    if (!err) {
      this.setState({ notes: res });
    } else {
      console.log(err);
    }
  });
}

但是错误仍然会发生,我相信它可能来自后端,我连接到数据库。

1 个答案:

答案 0 :(得分:0)

该错误表明您已经在::(任何IPv6)的端口5000上监听了其他内容。也许您在计算机上运行着另一个(较旧的)后端实例。 停止在端口5000上监听的所有内容,错误应该消失(直到您再次忘记)。