pg-promise: Connecting with "postgres://" does not work as it expects an object

The README says that you can use either an Object or an String to connect, but following code is not working:

var db = pgp("postgresq://user:password@host:port/database");

getting a run-time exception:

        throw new Error("Invalid parameter 'options' specified.");

Switched to an Object representation and worked like a charm.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

I should RTFM more carefully. Finally figured it out, thanks for answering.

You make the wrong call into the library object, not following the Getting Started instructions.

Your pgp object is set to require("pg-promise"), as opposed to:

require("pg-promise")(/*options*/)

As a result, you are making a call to initialize the library with options, but instead you are passing it the connection string, which is part of the next step - database initialization.

And as the library expects optional parameter options, giving it a connection string instead results in the error that you are seeing.