title: PostgreSQL query never resolves but shows no errors
body: <p>I am trying to make a simple GET route with express to retrieve all posts from my posts table. All queries work with my seed file <code>init_db.js</code>, but when I try Thunderclient or the browser it just never resolves and no errors are shown. I have used console logs in my <code>db/models/posts.js</code> and it hits <code>console.log('Beginning to get all posts')</code> but never hits the console log afterwards.</p>
  <p>Below is some of my code. I have omitted some extraneous code from these files for clarity and legibility.</p>
  <p><strong>api/posts.js</strong>:</p>
  <pre><code>const postsRouter = require('express').Router()
  const { createPost, getAllPosts } = require('../db/models/posts')
  
  postsRouter.use((req, res, next) =&gt; {
      console.log(`You've hit the Posts Router`)
      next()
  }) 
  
  postsRouter.get('/', async (req, res) =&gt; {
      try {
          const posts = await getAllPosts()
          res.send(posts)
      } catch(error) {
          console.log(error)
      }
  })
  
  module.exports = {
      postsRouter
  }
  </code></pre>
  <p><strong>db/models/posts.js</strong></p>
  <pre><code>const client = require(&quot;../client&quot;);
  
  async function createPostsTable() {
    try {
      await client.query(`
          CREATE TABLE posts
          (
              id SERIAL PRIMARY KEY,
              title VARCHAR(255) UNIQUE NOT NULL,
              content TEXT NOT NULL,
              &quot;videoURL&quot; TEXT,
              &quot;videoTitle&quot; VARCHAR(255),
              &quot;videoDescription&quot; TEXT,
              active BOOLEAN DEFAULT true
          );
          `);
    } catch (error) {
      console.log(&quot;Error building posts table!&quot;);
      throw error;
    }
  }
  
  async function getAllPosts() {
    console.log('Beginning to get all posts')
    try {
      const { rows: posts} = await client.query(`
        SELECT *
        FROM posts;
      `)
      console.log(posts)
      return posts
    } catch(error) {
      console.log('Error getting all posts')
      throw error
    }
  }
  
  module.exports = {
    createPostsTable,
    createPost,
    createInitialPosts,
    getAllPosts
  };
  </code></pre>
  <p><strong>index.js</strong>:</p>
  <pre><code>const express = require(&quot;express&quot;);
  const app = express();
  const PORT = 8080;
  
  const cors = require(&quot;cors&quot;);
  app.use(cors());
  
  app.use(express.json());
  
  const morgan = require(&quot;morgan&quot;);
  app.use(morgan('dev'));
  
  const path = require(&quot;path&quot;);
  app.use(express.static(path.join(__dirname, &quot;build&quot;)));
  
  app.use(&quot;/&quot;, (req, res, next) =&gt; {
    console.log('Body Logger Begin--&gt;')
    console.log(req.body)
    console.log('Body Logger End--&gt;')
    next()
  });
  
  app.use(&quot;/api&quot;, require(&quot;./api&quot;));
  
  app.use((req, res, next) =&gt; {
    res.sendFile(path.join(__dirname, &quot;build&quot;, &quot;index.html&quot;));
  });
  
  app.listen(
    PORT,
    () =&gt; {
      console.log(`Server is listening on PORT ${PORT}`);
    }
  );
  </code></pre>
  <p><strong>api/index.js</strong>:</p>
  <pre><code>const apiRouter = require('express').Router();
  const { postsRouter } = require('./posts')
  
  apiRouter.get('/', (req, res, next) =&gt; {
    res.send({
      message: 'API is under construction!',
    });
  });
  
  apiRouter.get('/health', (req, res, next) =&gt; {
    res.send({
      healthy: true,
    });
  });
  
  apiRouter.use('/posts', postsRouter)
  // place your routers here
  
  module.exports = apiRouter;
  </code></pre>
  <p>And my seed file which <strong>is able</strong> to successfully make queries
  <strong>init_db.js</strong>:</p>
  <pre><code>const { 
      client,
  } = require('./')
  
  const {
      createPostsTable,
      createInitialPosts,
      getAllPosts,
  } = require('./models/index')
  
  async function dropTables() {
      await client.query(`
          DROP TABLE IF EXISTS videos;
          DROP TABLE IF EXISTS posts;
      `)
  }
  
  async function buildTables() {
      try {
          client.connect();
  
          console.log('Starting to drop tables')
          await dropTables();
          console.log('Finished dropping tables')
          console.log('Starting to build tables')
          await createPostsTable();
          console.log('Finished building tables')
      } catch(error) {
          console.log(&quot;Error building tables&quot;)
          throw error;
      }
  }
  
  async function populateInitialData() {
      try {
          console.log('Starting to populate initial data')
          await createInitialPosts()
          console.log('Finished populating initial data')
  
      } catch(error) {
          console.log(&quot;Error populating initial data!&quot;)
          throw error
      }
  }
  
  async function testDB() {
      try {
          console.log('Starting to test the database')
          console.log(await getAllPosts())
          console.log('Finished testing the database')
  
      } catch(error) {
          console.log('Error testing database')
          throw error
      }
  }
  
  buildTables()
  .then(populateInitialData)
  .then(testDB)
  .catch(console.error)
  .finally(() =&gt; client.end())
  </code></pre>