title: How do I properly save this JSONB into PostgreSQL using node-postgres (pg)?
body: <p>So I have information coming in the GET URL, which needs to get passed into JSON and then saved (aggregated with increasing IDs to be correct) in the PostgreSQL DBMS. I wrote the following code, which seems to not save anything with no errors:</p>
  
  <pre><code>// Pg initialization
  const { Client } = require('pg')
  client = new Client({
      host: 'localhost',
      user: 'postgres',
      password: 'passwordhere',
      database: 'dbnamehere',
  });
  
  const createTableText = `
  CREATE EXTENSION IF NOT EXISTS "pgcrypto";
  CREATE TEMP TABLE IF NOT EXISTS cases (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    data JSONB
  );
  `
  
  app.get('/test', async function (req, res) {
    data = req.query.data;
    console.log(data);
    res.status(200).send(data);
  // create our temp table
  await client.query(createTableText)
  //const newUser = { email: 'test@test.com' }
  // create a new case
  await client.query('INSERT INTO cases(data) VALUES($1)', [data])
  const { rows } = await client.query('SELECT * FROM cases')
  console.log(rows)
    res.end();
  });
  
  
  </code></pre>
  
  <p>My package.json dependencies:</p>
  
  <pre><code>"dependencies": {
      "express": "^4.17.1",
      "mongoose": "^5.9.9",
      "pg": "^8.0.3"
    },
    "devDependencies": {}
  
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have this error handling code at the end of the file:</p>
  
  <pre><code> // Prints out more detailed errors
    if(process.env.NODE_ENV !== 'production') {
      process.once('uncaughtException', function(err) {
        console.error('FATAL: Uncaught exception.');
        console.error(err.stack||err);
        setTimeout(function(){
          process.exit(1);
        }, 100);
      });
    }
  </code></pre>
  
  <p>I also tried installing <code>npm install express-promise-router</code> and adding the following code but no errors were printed:</p>
  
  <pre><code>var router = require('express-promise-router')();
  router.use('/test', function (req, res) {
      return Promise.reject();
  })
  
  </code></pre>
  
  <p><strong>UPDATE2</strong>
  This code without closing it prints out the JSONB, not how do I save it?:</p>
  
  <pre><code>const connectionString=urlhere;
  const pool = new Pool({
      connectionString: connectionString,
    })
  
    const client = new Client({
      connectionString: connectionString,
    })
    client.connect()
  </code></pre>
  
  <p><strong>UPDATE3:</strong></p>
  
  <p>I removed the asynchronous code and made it synchronous. I get the following error messages now:</p>
  
  <pre><code>(node:10860) UnhandledPromiseRejectionWarning: Error: Connection terminated
      at Connection.&lt;anonymous&gt; (/path/here/node_mo
  dules/pg/lib/client.js:275:34)
      at Object.onceWrapper (events.js:299:28)
      at Connection.emit (events.js:215:7)
      at Socket.&lt;anonymous&gt; (/path/here/node_module
  s/pg/lib/connection.js:73:10)
      at Socket.emit (events.js:210:5)
      at TCP.&lt;anonymous&gt; (net.js:659:12)
  (node:10860) 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(). (rejectio
  n id: 1)
  (node:10860) [DEP0018] DeprecationWarning: Unhandled promise rejections are depr
  ecated. In the future, promise rejections that are not handled will terminate th
  e Node.js process with a non-zero exit code.
  (node:10860) UnhandledPromiseRejectionWarning: Error: Connection terminated
      at Connection.&lt;anonymous&gt; (/path/here/client.js:275:34)
      at Object.onceWrapper (events.js:299:28)
      at Connection.emit (events.js:215:7)
      at Socket.&lt;anonymous&gt; (/path/here/node_module
  s/pg/lib/connection.js:73:10)
      at Socket.emit (events.js:210:5)
      at TCP.&lt;anonymous&gt; (net.js:659:12)
  (node:10860) 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(). (rejectio
  n id: 2)
  (node:10860) UnhandledPromiseRejectionWarning: Error: Connection terminated
      at Connection.&lt;anonymous&gt; (/path/here/node_mo
  dules/pg/lib/client.js:275:34)
      at Object.onceWrapper (events.js:299:28)
      at Connection.emit (events.js:215:7)
      at Socket.&lt;anonymous&gt; (/path/here/node_module
  s/pg/lib/connection.js:73:10)
      at Socket.emit (events.js:210:5)
      at TCP.&lt;anonymous&gt; (net.js:659:12)
  (node:10860) 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(). (rejectio
  n id: 3)
  
  </code></pre>