首页 > 解决方案 > DEP0018 带快速 API

问题描述

我使用带有 typeorm 数据库的 express API 获取此错误代码:

(node:23162) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
(node:23162) 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:23162) [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.

我在我的 app.ts 中只使用了这个基本代码,并且在 sudo npm run build && sudo npm run start 之后错误仍然存​​在

createConnection().then(connection => {
    console.log("Try");
});

我也尝试将连接更改为异步,但仍然无法正常工作。

标签: expresstypeorm

解决方案


无论出于何种原因,您根本无法连接到数据库。这不是 ORM 本身的问题。检查您的配置,因为这绝对是问题所在。


推荐阅读