Node.js (节点:1184)未经处理的PromiserEjectionWarning:错误:connect-EconRefuse127.0.0.1:5432

Node.js (节点:1184)未经处理的PromiserEjectionWarning:错误:connect-EconRefuse127.0.0.1:5432,node.js,database,postgresql,pgadmin,Node.js,Database,Postgresql,Pgadmin,我正在尝试用Postgresql和PGAdmin V4.5连接NODE.JS。我有这个错误 (节点:1184)未经处理的PromiserEjectionWarning:错误:connect-EconRefuse127.0.0.1:5432 在TCPConnectWrap.afterConnect[完成时] 我试图用配置文件中的数据库URL修复它,但它不起作用 这是我的配置文件 module.exports = { DATABASE_URL: "192.168.x.xx",

我正在尝试用Postgresql和PGAdmin V4.5连接NODE.JS。我有这个错误

(节点:1184)未经处理的PromiserEjectionWarning:错误:connect-EconRefuse127.0.0.1:5432 在TCPConnectWrap.afterConnect[完成时]

我试图用配置文件中的数据库URL修复它,但它不起作用

这是我的配置文件

module.exports = {
  DATABASE_URL: "192.168.x.xx",
  HOST: "192.168.x.xx",
  PORT: "5432",
  USER: "postgres",
  PASSWORD: "xxxxx",
  DB: "public",
  dialect: "postgres",
};
控制器

const db = require("../config/db.config");
const { Pool } = require("pg");
const pool = new Pool(db);

// Retrieve all noticias from the database.
const getNews = (req, res) => {
  try {
    const result = pool.query("select * from noticias");
    res.send(result);
  } catch (err) {
    res.status(500).send({
      message: err.message || "Some error occurred.",
    });
  }
};

module.exports = {
  getNews,
};
Server.js

const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");

const app = express();

var corsOptions = {
  origin: "http://localhost:3000",
};

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("/", (req, res) => {
  res.json({ message: "Welcome to bezkoder application." });
});

// set port, listen for requests
require("./routes/noticias.routes")(app);

const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}.`);
});

路线

module.exports = (app) => {
  const noticias = require("../controllers/noticias.controller.js");

  var router = require("express").Router();

  router.get("/", noticias.getNews);

  app.use("/noticias", router);
};

编辑:我将配置更改为小写,现在我遇到了另一个问题。当我尝试进行SQL查询时,收到以下错误:

(节点:312)未处理的PromiserEjectionWarning:错误:不存在“通知”


不要在
db.config

db.config.js
已更正:

module.exports = {
  host: "192.168.x.xx",
  port: "5432",
  user: "postgres",
  password: "xxxxx",
  db: "public",
  dialect: "postgres",
};

请将node.js连接代码添加到postgresqlDone@JustinMartinDev