title: (node:1184) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
body: <p>Im trying yo connect NODE.JS with Postgresql and PGAdmin V4.5. I have this error</p>
  <blockquote>
  <blockquote>
  <p>(node:1184) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
  at TCPConnectWrap.afterConnect [as oncomplete]</p>
  </blockquote>
  </blockquote>
  <p>I tried to fixed it using DATABASE_URL in my config file but It dosn't work.</p>
  <p>This is my config file.</p>
  <pre><code>module.exports = {
    DATABASE_URL: &quot;192.168.x.xx&quot;,
    HOST: &quot;192.168.x.xx&quot;,
    PORT: &quot;5432&quot;,
    USER: &quot;postgres&quot;,
    PASSWORD: &quot;xxxxx&quot;,
    DB: &quot;public&quot;,
    dialect: &quot;postgres&quot;,
  };
  </code></pre>
  <p>Controller</p>
  <pre><code>const db = require(&quot;../config/db.config&quot;);
  const { Pool } = require(&quot;pg&quot;);
  const pool = new Pool(db);
  
  // Retrieve all noticias from the database.
  const getNews = (req, res) =&gt; {
    try {
      const result = pool.query(&quot;select * from noticias&quot;);
      res.send(result);
    } catch (err) {
      res.status(500).send({
        message: err.message || &quot;Some error occurred.&quot;,
      });
    }
  };
  
  module.exports = {
    getNews,
  };
  </code></pre>
  <p>Server.js</p>
  <pre><code>const express = require(&quot;express&quot;);
  const bodyParser = require(&quot;body-parser&quot;);
  const cors = require(&quot;cors&quot;);
  
  const app = express();
  
  var corsOptions = {
    origin: &quot;http://localhost:3000&quot;,
  };
  
  app.use(cors(corsOptions));
  
  // parse requests of content-type - application/json
  app.use(bodyParser.json());
  
  // parse requests of content-type - application/x-www-form-urlencoded
  app.use(bodyParser.urlencoded({ extended: true }));
  
  // simple route
  app.get(&quot;/&quot;, (req, res) =&gt; {
    res.json({ message: &quot;Welcome to bezkoder application.&quot; });
  });
  
  // set port, listen for requests
  require(&quot;./routes/noticias.routes&quot;)(app);
  
  const PORT = process.env.PORT || 8080;
  app.listen(PORT, () =&gt; {
    console.log(`Server is running on port ${PORT}.`);
  });
  
  </code></pre>
  <p>Routes</p>
  <pre><code>module.exports = (app) =&gt; {
    const noticias = require(&quot;../controllers/noticias.controller.js&quot;);
  
    var router = require(&quot;express&quot;).Router();
  
    router.get(&quot;/&quot;, noticias.getNews);
  
    app.use(&quot;/noticias&quot;, router);
  };
  
  </code></pre>
  <p>EDIT: I changed the config to lowercase and now I have another problem. When I try to make a SQL query I recieve this error:</p>
  <blockquote>
  <blockquote>
  <p>(node:312) UnhandledPromiseRejectionWarning: error: no existe la relación «noticias»</p>
  </blockquote>
  </blockquote>