# Add e-signatures and clickwrap to a Heroku app

> Add e-signatures and clickwrap to a Heroku app: the esigncomply package in a Node.js web dyno, the key in a config var, and Heroku Postgres for receipts.

Source: https://esigncomply.com/heroku

Platform · Heroku

To add e-signatures and clickwrap to a Heroku app, run the `esigncomply` package in a Node.js web dyno and keep the secret key in a config var. The dyno creates the session and confirms the record, and Heroku Postgres keeps the pinned versions and the receipt, because dynos share nothing. Esign Comply seals each acceptance as an independent record.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/heroku)

`npm install esigncomply pg`

[Heroku quickstart](https://esigncomply.com/docs/quickstart/heroku)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run locally for Heroku before publishing

**Web dyno**

server.js (excerpt)

```js
// Step 4: create the session with the secret key. The browser gets the client token only.
if (req.method === "POST" && url.pathname === "/api/ceremony") {
  const { data: session, error } = await esc.sessions.create(
    {
      profile: process.env.ESIGNCOMPLY_PROFILE_ID,
      signer,
      documents: [
        { document: DOCUMENTS.terms, version: "current" },
        { document: DOCUMENTS.privacy, version: "current" },
      ],
      // The page that runs the ceremony: the origin the browser reports, plus its path.
      context: { url: `${req.headers.origin ?? url.origin}/signup`, locale: "en-US", purpose: "account_signup" },
    },
    { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` },
  );
  if (error) return json(res, 502, { error: error.code });
  // In Postgres, not in memory: the router can send the confirmation to another dyno.
  await savePinned(signer.external_id, session.documents.map((d) => d.version_id).sort());
  return json(res, 200, { clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
}
```

**Release phase**

`migrate.js`

```js
// migrate.js: the release phase command. Heroku runs it in a one-off dyno before each new release is deployed.
import { close, migrate } from "./store.js";

// CREATE TABLE IF NOT EXISTS: a config var change makes a release too, and this runs again.
await migrate();
console.log("table esc_acceptances ready");
await close();
```

**Confirm**

server.js (excerpt)

```js
// Step 6: confirm the record with the secret key before the account exists.
if (req.method === "POST" && url.pathname === "/api/signup/confirm") {
  const { recordId } = await body(req);
  const { data: record, error } = await esc.records.get(String(recordId));
  const expected = await getPinned(signer.external_id);
  const confirmed =
    !error &&
    SEALED.includes(record.status) &&
    record.livemode === LIVE &&
    record.signer.external_id === signer.external_id &&
    expected.length > 0 &&
    JSON.stringify(record.documents.map((d) => d.version_id).sort()) === JSON.stringify(expected);
  console.log(confirmed ? `confirmed ${record.id} (${record.status})` : "refused");
  if (!confirmed) return json(res, 409, { confirmed: false });
  // Only now create the account. The record ID and the receipt go in the same row.
  await saveReceipt(signer.external_id, record.id, record.receipt);
  return json(res, 200, { confirmed: true, recordId: record.id });
}
```

**Postgres store**

store.js (excerpt)

```js
// Heroku Postgres sets the config var DATABASE_URL and can change its value: read it at start, never copy it.
// TLS is not set here. Heroku Postgres requires it, so the app has the config var PGSSLMODE=no-verify,
// which pg reads itself. The Postgres on your machine has no TLS, and there the variable is not set.
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
// When the database closes an idle connection, the pool emits an error. With no listener, Node.js exits.
pool.on("error", (error) => console.error(`postgres: ${error.message}`));

// One row per signer: the versions the session pinned, then the record and its receipt.
export async function migrate() {
  await pool.query(`
    CREATE TABLE IF NOT EXISTS esc_acceptances (
      signer_id    text PRIMARY KEY,
      version_ids  jsonb NOT NULL,
      record_id    text,
      receipt      text,
      confirmed_at timestamptz
    )`);
}

export async function savePinned(signerId, versionIds) {
  await pool.query(
    `INSERT INTO esc_acceptances (signer_id, version_ids) VALUES ($1, $2)
     ON CONFLICT (signer_id) DO UPDATE SET version_ids = EXCLUDED.version_ids`,
    [signerId, JSON.stringify(versionIds)],
  );
}

export async function getPinned(signerId) {
  const { rows } = await pool.query("SELECT version_ids FROM esc_acceptances WHERE signer_id = $1", [signerId]);
  return rows[0]?.version_ids ?? [];
}
```

Integrate with Heroku

## How do you integrate Esign Comply with Heroku?

On Heroku the server half is one web dyno started from a `Procfile`. Heroku sets `PORT`, sends `SIGTERM` before it stops a dyno, and runs `node migrate.js` in the release phase before each release is deployed. Dynos share no files and the routers pick one at random, so the pinned versions go to Heroku Postgres.

Heroku lets you deploy, run and manage apps written in Ruby, Node.js, Java, Python, Clojure, Scala, Go, PHP and .NET.

Source: [Heroku Dev Center, How Heroku Works](https://devcenter.heroku.com/articles/how-heroku-works), read on November 26, 2026.

[Heroku quickstart](https://esigncomply.com/docs/quickstart/heroku) · [All platforms](https://esigncomply.com/platforms)

Where each part lives on Heroku

- **Web dyno** · `server.js`
- **Release phase** · `migrate.js`
- **Confirm** · `server.js`
- **Postgres store** · `store.js`

Run on 2026-11-26 in the image that Heroku's Cloud Native Buildpacks built from this code (pack 0.40.11 with the builder heroku/builder:24, heroku/nodejs 5.9.2 and heroku/procfile 4.2.4, Node.js 26.13.1 on Ubuntu 24.04), started the way a web dyno is (PORT, DYNO, the web and release process types of the Procfile, SIGTERM) with PostgreSQL 17.12 in a container in place of Heroku Postgres, with esigncomply 1.0.4, pg 8.23.1, the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode. The same code also ran under heroku local (Heroku CLI 11.14.0) and under Node.js 24.22.1 on the machine. The Heroku settings are from Heroku's documentation as of that date, the heroku commands in step 8 were not run, and app.json was not read by Heroku. Nothing has been deployed to Heroku yet.

Three steps

## How does Esign Comply fit with Heroku?

Each step uses a feature Heroku already has. The secret key stays on the server side of Heroku in all three.

1. **A config var holds the key**

   Set `ESIGNCOMPLY_API_KEY` with `heroku config:set` or in the app's Settings tab. Heroku exposes config vars to the dyno as environment variables, and the SDK reads the key from `process.env`. Each app has its own config vars, so the live key exists in the production app only. Source: [Heroku Dev Center, Configuration and Config Vars](https://devcenter.heroku.com/articles/config-vars), read on November 26, 2026.

2. **The web dyno creates the session**

   `web: node server.js` in the `Procfile` is the one process type that receives HTTP traffic from Heroku's routers. `POST /api/ceremony` calls `esc.sessions.create` there and returns the client token. The same dyno serves the signup page, and the browser SDK records the ceremony from the signer's device. Source: [Heroku Dev Center, The Procfile](https://devcenter.heroku.com/articles/procfile), read on November 26, 2026.

3. **Heroku Postgres keeps the receipt**

   The session route stores the pinned versions in a table in Heroku Postgres, which the dyno reaches through `DATABASE_URL`. The confirm route reads the record with the secret key, compares it with the row, and writes the record ID and the receipt into it. The release phase command creates the table. Source: [Heroku Dev Center, Provisioning Heroku Postgres](https://devcenter.heroku.com/articles/provisioning-heroku-postgres), read on November 26, 2026.

Heroku setup

## Where do the key, the preview hosts and the webhook go on Heroku?

Four settings carry an Esign Comply integration on Heroku. What is said here about Heroku was read from its own documentation, and the quickstart has each command.

### Config vars

Each Heroku app has its own values: the production app holds the live key, the live IDs and `ESIGNCOMPLY_LIVE=true`, every other app the test key and the test IDs. Heroku's documentation says setting or removing a config var restarts the app and creates a new release. On your machine the values go in `.env`, which `heroku local` reads and Git never sees.

Source: [Heroku Dev Center, Configuration and Config Vars](https://devcenter.heroku.com/articles/config-vars), read on November 26, 2026.

### The Procfile and the release phase

`release: node migrate.js` runs in a one-off dyno whenever a new release is created, and Heroku does not deploy a release whose command fails. Start the web process with `node server.js`: Heroku sends `SIGTERM` to every process of a dyno and `SIGKILL` 30 seconds later. In the test the process closed its pool and exited with code 0.

Source: [Heroku Dev Center, Release Phase](https://devcenter.heroku.com/articles/release-phase), read on November 26, 2026.

### Review apps and test mode

Review apps need an `app.json` in the repository, and Heroku injects the pipeline's Review app config vars into each one: put the test key there. Each review app answers on a host of its own under `herokuapp.com`. List that exact host under Domains in the Esign Comply dashboard as a test origin, never the shared suffix.

Source: [Heroku Dev Center, Review Apps](https://devcenter.heroku.com/articles/github-integration-review-apps), read on November 26, 2026.

### The registered domain and the webhook

Add your custom domain with `heroku domains:add`, then register it and verify it with one DNS record. Heroku's documentation says the `herokuapp.com` domain always remains active, so redirect it to your domain. A production app on its `herokuapp.com` host verifies with a file at `/.well-known/esigncomply.txt`. For the `record.completed` webhook, add a route to the app and register its production URL under Webhooks in the Esign Comply dashboard.

Source: [Heroku Dev Center, Custom Domain Names for Apps](https://devcenter.heroku.com/articles/custom-domains), read on November 26, 2026.

Read on November 26, 2026: [Heroku Dev Center, Configuration and Config Vars](https://devcenter.heroku.com/articles/config-vars), [Heroku Dev Center, The Procfile](https://devcenter.heroku.com/articles/procfile), [Heroku Dev Center, Release Phase](https://devcenter.heroku.com/articles/release-phase), [Heroku Dev Center, Dynos](https://devcenter.heroku.com/articles/dynos), [Heroku Dev Center, Dyno Restarts](https://devcenter.heroku.com/articles/dyno-restarts), [Heroku Dev Center, Dyno Startup Behavior](https://devcenter.heroku.com/articles/dyno-startup-behavior), [Heroku Dev Center, Dyno Shutdown Behavior](https://devcenter.heroku.com/articles/dyno-shutdown-behavior), [Heroku Dev Center, HTTP Routing](https://devcenter.heroku.com/articles/http-routing), [Heroku Dev Center, Connecting to Heroku Postgres](https://devcenter.heroku.com/articles/connecting-heroku-postgres), [Heroku Dev Center, Provisioning Heroku Postgres](https://devcenter.heroku.com/articles/provisioning-heroku-postgres), [Heroku Dev Center, Review Apps](https://devcenter.heroku.com/articles/github-integration-review-apps), [Heroku Dev Center, app.json Schema](https://devcenter.heroku.com/articles/app-json-schema), [Heroku Dev Center, Custom Domain Names for Apps](https://devcenter.heroku.com/articles/custom-domains), [Heroku Dev Center, Managing Buildpacks](https://devcenter.heroku.com/articles/managing-buildpacks), [Heroku Dev Center, Node.js Support Reference](https://devcenter.heroku.com/articles/nodejs-support), [Heroku Dev Center, Running Apps Locally](https://devcenter.heroku.com/articles/heroku-local).

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Heroku app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes on Heroku, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap on Heroku

```
Add Esign Comply clickwrap to my app on Heroku: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/heroku.md (the steps and the tested code for Heroku)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Heroku facts
- Packages (the only ones that exist): esigncomply (server, Node.js 20.19 or later, an ES module) and @esigncomply/browser. Without a bundler, load the browser SDK from https://esigncomply.com/sdk/v1/esigncomply.js.
- The secret key is the config var ESIGNCOMPLY_API_KEY, set on each Heroku app. Never commit it, never put it in app.json, never print it. For review apps it goes under Review app config vars in the pipeline's settings.
- The Procfile names the processes: "web: node server.js" and "release: node migrate.js". Listen on the port in PORT and name no host in listen(): Fir expects [::], Cedar the port.
- Dynos share no memory and no files, and the router picks a web dyno at random. Keep the pinned version IDs in Heroku Postgres (DATABASE_URL), never in a variable of the process or in a file.
- Heroku Postgres requires TLS. Leave the ssl option out of the code and set the config var PGSSLMODE=no-verify on Heroku. Do not set it on a machine whose Postgres has no TLS.
- The release command runs before every new release, a config var change included: it must be safe to run again (CREATE TABLE IF NOT EXISTS).
- Handle SIGTERM: Heroku sends it to every process of a dyno and kills what is left 30 seconds later.
- Expect live records only where the config var ESIGNCOMPLY_LIVE is "true": the production app.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Server: POST /api/ceremony creates the session with esc.sessions.create and an Idempotency-Key, saves the signer ID and the pinned version IDs in Postgres, and returns only clientToken, apiUrl and documents.
4. Server: GET /legal/terms and /legal/privacy render the registered version from esc.documents.versions.getContent inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Server: POST /api/signup/confirm reads the record with esc.records.get and requires: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the row in Postgres. Only then create the account, and store the record ID and the receipt in the same row.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:3000/signup --callback http://localhost:3000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures on Heroku?

These are specific to Heroku. Each one was seen while the quickstart's code was run, or is in Heroku's own documentation.

- **Heroku Postgres requires TLS, and pg does not turn it on**

  Heroku's documentation says Heroku Postgres requires SSL connections, and shows `rejectUnauthorized: false` or the config var `PGSSLMODE=no-verify` for Node.js. In the test, `pg` 8.23.1 with neither was refused by a TLS-only Postgres with `no pg_hba.conf entry ... no encryption`, and the release command exited with code 1. With `PGSSLMODE=no-verify` it connected over TLS 1.3. The same variable failed against a local Postgres without TLS.

  Source: [Heroku Dev Center, Connecting to Heroku Postgres](https://devcenter.heroku.com/articles/connecting-heroku-postgres), read on November 26, 2026.

- **A config var change runs the release command again**

  Heroku's documentation says setting a config var creates a new release, and that the `release` command runs whenever a new release is created. So `migrate.js` runs more often than you deploy. In the test the `release` process of the image ran twice against the same database and exited with code 0 both times, because the table is created with `IF NOT EXISTS`.

  Source: [Heroku Dev Center, Release Phase](https://devcenter.heroku.com/articles/release-phase), read on November 26, 2026.

- **Naming 0.0.0.0 in listen() leaves IPv6 unanswered**

  Heroku's documentation says a web dyno of a Fir app must bind on IPv6, `[::]:$PORT`, within 60 seconds of startup, and a Cedar app to `$PORT`. In the test a server that named `0.0.0.0` in `listen()` answered on IPv4 only. With no host named, Node.js answered on `127.0.0.1` and on `[::1]`. The quickstart passes the port and nothing else.

  Source: [Heroku Dev Center, Dyno Startup Behavior](https://devcenter.heroku.com/articles/dyno-startup-behavior), read on November 26, 2026.

## Where are the Heroku quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Heroku quickstart](https://esigncomply.com/docs/quickstart/heroku)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature on Heroku?

The same record on every stack and platform. Your Heroku code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures on Heroku

### How does test mode work on Heroku review apps?

Each review app gets a host of its own under `herokuapp.com`, random by default, which a test key refuses until you list that exact host under Domains as a test origin. Put the test key under Review app config vars in the pipeline's settings: Heroku injects those into every review app. On `localhost` a test key works with no setup.

### Where should the receipt be stored on Heroku?

In Heroku Postgres, beside the signer ID and the record ID. The confirm route writes both once the record is confirmed. Heroku's documentation says each dyno has its own ephemeral filesystem, discarded when the dyno restarts, so a file is no place for it.

### Why does the quickstart set PGSSLMODE and pass no ssl option?

So the same code runs on Heroku and on your machine. Heroku Postgres requires TLS, and Heroku documents both the `ssl` object and the config var `PGSSLMODE=no-verify`. In the test both connected over TLS to a TLS-only Postgres, and both failed against a local Postgres without TLS. A config var can differ from app to app.

### Does a config var change run the release phase?

Yes. Heroku's documentation says a change to a config var creates a new release, and the `release` command runs for it, unless the change comes from an add-on's config vars. The quickstart's command creates the table only if it does not exist: run twice in the test, it exited with code 0 both times.

### What was run with Heroku's own tools, and what was not?

Heroku's builder `heroku/builder:24` built the image with `pack`, its `web` and `release` processes ran in Docker against a Postgres container, and `heroku local` from CLI 11.14.0 recorded a signature. Nothing was deployed: config vars, the release phase, the routers, review apps, Heroku Postgres and custom domains on Heroku are proven only by a deployment.

### Other platforms

- [Railway](https://esigncomply.com/railway)
- [Render](https://esigncomply.com/render)
- [Fly.io](https://esigncomply.com/fly-io)

### Stacks used with Heroku

- [Node.js](https://esigncomply.com/nodejs)
- [Express](https://esigncomply.com/express)
- [Next.js](https://esigncomply.com/nextjs)

[All platforms](https://esigncomply.com/platforms) · [All stacks](https://esigncomply.com/stacks) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Run the signing flow in your Heroku app. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/heroku)

Free plan: 10 live signatures a month and a full test mode. No card required.

Heroku is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Heroku is from Heroku's documentation or from a test run, as marked, on November 26, 2026. `/heroku.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
