Getting started with Postgres and Node.js
@databases/pg library provides a safe and convenient API for querying postgres databases in node.js.
Top tip: If you haven't done so already, you may want to set up syntax highighting in your editor then resume this guide when you've done that.
If you're new to
@databases, the best way to start is by following our guide in order:
Installation & Setup - install
@databases/pgand run your first query
Managing Connections - manage the connection pool and connection configuration securely
Querying Postgres - perform CRUD (create, read, update, delete) operations in Postgres
Using Transactions - isolate concurrent queries using transactions
TypeScript - generate TypeScript types for your database tables
Logging & Debugging - log queries for easier debugging, and to help find performance bottlenecks
Migrations - use "migrations" to keep your database schema consistent between environments
Testing - use docker to create temporary databases for integration tests
If you're using TypeScript or babel, you can use the modern
import createConnectionPool from '@databases/pg';