$ npm install pg-promise


Loading and initializing the library with Initialization Options:

const initOptions = {/* initialization options */};
const pgp = require('pg-promise')(initOptions);

− or without Initialization Options:

const pgp = require('pg-promise')();


Create your Database object from the connection as pgp(connection, [dc]):

const db = pgp(connection);

Object db represents the Database protocol with lazy connection, i.e. only the actual query methods acquire and release the connection automatically. Therefore, you should create only one global/shared db object per connection details.

It is best to initialize the library and create Database in its own module, see Where should I initialize pg-promise.


Learn by Example is the best quick-start tutorial. For everything else see the WiKi pages.


External Resources

Main Types

  • Database - database-level methods and properties
  • Task - extends Database with task-level methods and properties

Special Types



  • connect - connecting to the database
  • disconnect - disconnecting from the database
  • query - executing a query
  • task - task start/end events
  • transact - transaction start/end events
  • receive - receiving data from a query
  • error - global error handler
  • extend - interface extension event