Node.js服务器突然无法工作

时间:2018-09-10 14:15:12

标签: node.js mongodb mongoose

昨天工作正常,现在给我这个错误。我创建的API正常运行,所有请求均正常运行,现在我不知道出了什么问题。

我在Angular应用程序中使用了ng serve,在API服务器中使用了node app.js,并且一切正常,为什么现在不连接呢?

Running on port 4000...
(node:13096) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:13096) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection 0 to localhost:27017 timed out]
    at Pool.<anonymous> (C:\Users\Heiko\Documents\parkingApi\node_modules\mongodb-core\lib\topologies\server.js:564:11)
    at Pool.emit (events.js:182:13)
    at Connection.<anonymous> (C:\Users\Heiko\Documents\parkingApi\node_modules\mongodb-core\lib\connection\pool.js:317:12)
    at Object.onceWrapper (events.js:273:13)
    at Connection.emit (events.js:182:13)
    at Socket.<anonymous> (C:\Users\Heiko\Documents\parkingApi\node_modules\mongodb-core\lib\connection\connection.js:257:10)
    at Object.onceWrapper (events.js:273:13)
    at Socket.emit (events.js:182:13)
    at Socket._onTimeout (net.js:448:8)
    at ontimeout (timers.js:424:11)
    at tryOnTimeout (timers.js:288:5)
    at listOnTimeout (timers.js:251:5)
    at Timer.processTimers (timers.js:211:10)
(node:13096) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13096) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

1 个答案:

答案 0 :(得分:1)

该日志清楚地表明您的节点服务器无法连接到MongoDB。原因可能是任何。让我列出一些可能性。

  • MongoDB服务器已关闭。您可能需要重新启动
  • 您的节点服务器可能位于某些防火墙之后,该防火墙不允许DB连接到外部DB。

您可以使用以下方法从Shell检查连接:

mongod "mongodb_host_url"