Score:0

Express not fetching data from postgres database. No errors displayed

cn flag

This is a difficult question for me to ask because I'm not truly sure what the issue is.

I have an Express JS server for routing and Node Postgres (PG) for the pool.

When I either go directly to localhost or use POSTMAN to test the routes there is no response except a simple loading screen. With POSTMAN, it gets stuck like so:

POSTMAN sending request...

Or for localhost it simply stays buffering/loading.

I am following this video on how to deploy a PERN app to Heroku. However, even after cloning the repo and updating all the packages within I cannot fetch data from my database (I am using PostgreSQL). I have updated all the database login information so it's not that.

Below is my code:

Server:

const express = require("express");
const app = express();
const cors = require("cors");
const pool = require("./db");

app.use(cors());
app.use(express.json());

app.get("/todos", async (req, res) => {
  try {
    const allTodos = await pool.query("SELECT * FROM todo");
  } catch (err) {
    console.error(err.message);
  }
});

app.get("*", (req, res) => {
  res.send("TEST");
});

app.listen(5000, () => {
  console.log("server has started on port 5000");
});

Pool

const Pool = require("pg").Pool;

const pool = new Pool({
  user: "postgres",
  password: "postgres",
  host: "localhost",
  port: 5432,
  database: "perntodo"
});

module.exports = pool;

All pool information is correct.

I have checked my database and there are active tables and data.

Again, there are no errors displayed so it's super hard for me to diagnose the problem.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.