Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pg-promise TypeError: Invalid "options" parameter

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;
like image 304
kevin Avatar asked Dec 18 '25 21:12

kevin


1 Answers

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')();
like image 86
xSynergyx Avatar answered Dec 21 '25 12:12

xSynergyx