简体   繁体   中英

Error: connect ECONNREFUSED 127.0.0.1:5432 heroku

I'm not really sure why I'm getting this. When I went to launch the app on Heroku i received a 404 error with message of not found and it's from my error handler in my app.js file, but I'm unsure what is going on.

Everything works locally??

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

please post your server.js code and Procfile. Also by looking the error, it seems that you have used your localhost PostgreSQL host but you PostgreSQL on heroku, are you sure the addons is included in heroku? If it is added then on connection code, you need to use the that url to work. Example could be as below

    connectionString = 'postgresql://dbuser:secretpassword@database.server.com:3211/mydb'

Use like this:

    const { Pool, Client } = require('pg')
    const connectionString = 'postgresql://dbuser:secretpassword@database.server.com:3211/mydb'

    const pool = new Pool({
        connectionString: connectionString,
    })

or like this

    var client = new Client({
        user: "username",
        password: "pwd",
        database: "dbname",
        port: 5432,
        host: "host",
        ssl: true
    });
    client.connect(function () {
        console.log("connected");
    });

you could find the explanation here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM