I am trying to set up a Postgres database in a nodejs server using ES6 syntax, but I don't think I'm importing and initializing pg-promise properly. If I were using common js sytax I would do the below:
// Create Database Connection
const pgp = require('pg-promise')({});
const db = pgp(config.db);
// Test connection
db.connect()
.then((obj) => {
console.log('Connected to database');
obj.done(); // success, release connection;
})
.catch((error) => {
console.error('ERROR:', error.message);
});
Using ES6 I am trying to do the below but the connection just hangs and doesn't complete or error out.
import pgPromise from 'pg-promise';
// Create Database Connection
const pgp = pgPromise({});
const db = pgp(config.db);
// Test connection
db.connect()
.then((obj) => {
console.log('Connected to database');
obj.done(); // success, release connection;
})
.catch((error) => {
console.error('ERROR:', error.message);
});
I've searched through the pg-promise docs and can't find anything about using it with ES6 syntax. Any ideas on what I should change?