Applications and operations

Connect to PostgreSQL from Node.js

Optionally connect from Node.js with pg, a secret connection URL, bounded waits, and deliberate TLS settings.

8 minute lesson

~~~

The application lessons use Node.js as an optional track. You can follow the database and operations lessons without it.

Install the pg driver:

npm install pg

Keep the connection URL in deployment secrets:

postgresql://notes_app:password@localhost:5432/notes_app

Do not commit it, print it, or send it to browser code. A hosted provider may give you separate direct and pooled URLs.

For a remote database, follow the provider’s TLS instructions and verify its certificate. Do not silence certificate errors with rejectUnauthorized: false.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →