![](/img/trans.png)
[英]ERROR: connect ECONNREFUSED 127.0.0.1:5432 on Gitlab CI
[英]Error: connect ECONNREFUSED 127.0.0.1:5432 heroku
我不太確定為什么我會得到這個。 當我在 Heroku 上啟動該應用程序時,我收到了一條 404 錯誤,其中包含未找到的消息,它來自我的 app.js 文件中的錯誤處理程序,但我不確定發生了什么。
一切都在本地工作?
server.js
/** Start server for jobly. */
const app = require('./app');
const { PORT } = require("./config");
app.listen(PORT, function () {
console.log(`Server starting on port ${PORT}!`);
});
2020-07-17T03:49:35.103011+00:00 heroku[web.1]: Starting process with command `node server.js`
2020-07-17T03:49:39.311369+00:00 app[web.1]: Using database jobly-db
2020-07-17T03:49:39.885564+00:00 app[web.1]: Server starting on port 6266!
2020-07-17T03:49:39.894114+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
2020-07-17T03:49:39.894116+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
2020-07-17T03:49:39.894367+00:00 app[web.1]: (node:4) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2020-07-17T03:49:39.894527+00:00 app[web.1]: (node:4) [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.
2020-07-17T03:49:40.080034+00:00 heroku[web.1]: State changed from starting to up
2020-07-17T03:52:04.190766+00:00 app[api]: Attach DATABASE (@ref:postgresql-convex-54039) by user areacodelogic@gmail.com
請發布您的 server.js 代碼和 Procfile。 另外通過查看錯誤,似乎您已經使用了本地主機 PostgreSQL 主機,但您在 heroku 上使用了 PostgreSQL,您確定插件包含在 heroku 中嗎? 如果添加了連接代碼,則需要使用 url 才能工作。 示例如下
connectionString = 'postgresql://dbuser:secretpassword@database.server.com:3211/mydb'
像這樣使用:
const { Pool, Client } = require('pg')
const connectionString = 'postgresql://dbuser:secretpassword@database.server.com:3211/mydb'
const pool = new Pool({
connectionString: connectionString,
})
或者像這樣
var client = new Client({
user: "username",
password: "pwd",
database: "dbname",
port: 5432,
host: "host",
ssl: true
});
client.connect(function () {
console.log("connected");
});
你可以在這里找到解釋
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.