Add e-signatures and clickwrap to a Heroku app
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.
$npm install esigncomply pgFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// 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 }); }
// 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();
// 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 }); }
// 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 ?? []; }
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, read on .- Web dynoserver.js
- Release phasemigrate.js
- Confirmserver.js
- Postgres storestore.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.
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.
- 01A config var holds the keySet
ESIGNCOMPLY_API_KEYwithheroku config:setor in the app's Settings tab. Heroku exposes config vars to the dyno as environment variables, and the SDK reads the key fromprocess.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, read on . - 02The web dyno creates the session
web: node server.jsin theProcfileis the one process type that receives HTTP traffic from Heroku's routers.POST /apicalls/ceremony esc.sessions.createthere 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, read on . - 03Heroku Postgres keeps the receiptThe 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, read on .
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, read on .
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, read on .
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, read on .
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. 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, read on .
Read on : Heroku Dev Center, Configuration and Config Vars, Heroku Dev Center, The Procfile, Heroku Dev Center, Release Phase, Heroku Dev Center, Dynos, Heroku Dev Center, Dyno Restarts, Heroku Dev Center, Dyno Startup Behavior, Heroku Dev Center, Dyno Shutdown Behavior, Heroku Dev Center, HTTP Routing, Heroku Dev Center, Connecting to Heroku Postgres, Heroku Dev Center, Provisioning Heroku Postgres, Heroku Dev Center, Review Apps, Heroku Dev Center, app.json Schema, Heroku Dev Center, Custom Domain Names for Apps, Heroku Dev Center, Managing Buildpacks, Heroku Dev Center, Node.js Support Reference, Heroku Dev Center, Running Apps Locally.
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. Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The prompt generator writes the long version, with your own document and profile IDs.
Pages for each AI toolAdd 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.mdWhat 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.
- 01
Heroku Postgres requires TLS, and pg does not turn it on
Heroku's documentation says Heroku Postgres requires SSL connections, and shows
Source: Heroku Dev Center, Connecting to Heroku Postgres, read on .rejectUnauthorized: falseor the config varPGSSLMODE=no-verifyfor Node.js. In the test,pg8.23.1 with neither was refused by a TLS-only Postgres withno pg_hba.conf entry ... no encryption, and the release command exited with code 1. WithPGSSLMODE=no-verifyit connected over TLS 1.3. The same variable failed against a local Postgres without TLS. - 02
A config var change runs the release command again
Heroku's documentation says setting a config var creates a new release, and that the
Source: Heroku Dev Center, Release Phase, read on .releasecommand runs whenever a new release is created. Somigrate.jsruns more often than you deploy. In the test thereleaseprocess of the image ran twice against the same database and exited with code 0 both times, because the table is created withIF NOT EXISTS. - 03
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,
Source: Heroku Dev Center, Dyno Startup Behavior, read on .[::]:$PORT, within 60 seconds of startup, and a Cedar app to$PORT. In the test a server that named0.0.0.0inlisten()answered on IPv4 only. With no host named, Node.js answered on127.0.0.1and on[::1]. The quickstart passes the port and nothing else.
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.
- QuickstartHeroku quickstartStep by step, from install to your first sealed test record, with every file and the output of each step.Open
- ReferenceAPI referenceEvery endpoint, field and error code. Sessions, records and documents are the three this page uses.Open
- GuideServer confirmationThe one place access is granted: what to compare, and the webhook that backs the check up.Open
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.
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, andGET /v1returns it again./records /{id} /receipt 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.
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.
Run the signing flow in your Heroku app. Leave the record to us.
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 . /heroku.md is this page as Markdown.