Installation
Install postgrejs with npm:
npm install postgrejs
Requirements
node >= 20.x
Module format
postgrejs ships as an ES module ("type": "module"). Node 20.19+ and 22.12+ support require()-ing an ESM
package directly from CommonJS code, so you can use either import or require() depending on your project's
module system:
// ESM
import { Connection } from 'postgrejs';
// CommonJS (Node 20.19+ / 22.12+)
const { Connection } = require('postgrejs');
On older Node 20/22 releases that don't support requiring ESM, import postgrejs from an ESM entry point (e.g. a
dynamic import(), or a project configured with "type": "module").
Next, see Single Connection to open your first connection.