---
schema_version: "1"
id: 1f57a40333427b1050b7be507aa55aac08c708896a2e78bc1a8472807de9b30c
title: Create a Heroku Postgres Client in Node.js
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-functions/functions/guide/dev-guide/heroku-postgres-js.md
canonical_url: https://developer.salesforce.com/docs/platform/functions/guide/heroku-postgres-js.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: df5cb5299aa93b89d0782832a8b5a8e28b0206822bc96c49e6d9c979347e032c
products:
  - Salesforce Functions
---
# Create a Heroku Postgres Client in Node.js

For Salesforce Functions written in Node.js, use the [node-postgres](https://node-postgres.com/) (pg) package to access your Heroku PostgreSQL database. Access the `DATABASE_URL` environment variable with `process.env` to create a Postgres client instance.

```javascript
import { Client } from "pg";
async function pgConnect() {
  const DATABASE_URL = process.env.DATABASE_URL;
  if (!DATABASE_URL) {
    throw new Error("DATABASE_URL is not set");
  }
  // Connect to PostgreSQL
  const client = new Client({
    connectionString: DATABASE_URL,
    ssl: {
      rejectUnauthorized: false,
    },
  });

  await client.connect();
  return client;
}
```
