I am trying to change my files from using the pg package to the pg-promise package. Everything was working fine with the initial pg solution I was using. However, switching over to pg-promise and using the documentation I am getting strange errors during setup.
The latest error:
throw new TypeError('Invalid "options" parameter: ' + JSON.stringify(options));
^
TypeError: Invalid "options" parameter: "postgres://me:complete@localhost:5432/education_be"
My config file:
require('dotenv').config();
const pgp = require('pg-promise');
// === My initial setup just using 'pg'
// const { Pool } = require('pg');
// const pool = new Pool({
// name: process.env.name,
// password: process.env.password,
// host: process.env.host,
// database: 'education_be',
// port: process.env.port
// });
// === My first attempt following the guide would receive errors like:
// === Error: Option "user" is not recognized.
const connection = {
name: 'me',
password: 'password',
host: 'localhost',
database: 'education_be',
port: 5432
};
// === attempting (unsuccessfully) to just use the address
const db = pgp('postgres://me:complete@localhost:5432/education_be');
module.exports = db;
I'm late but hoping this helps others who encounter the same issue. Although you have no options you must include the parentheses in the pg-promise require statement.
const pgp = require('pg-promise')();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With