# Add e-signatures and clickwrap to a Railway app

> Add e-signatures and clickwrap to a Railway app: the esigncomply package in a Node.js service, the key in a sealed variable, and Railway Postgres.

Source: https://esigncomply.com/railway

Platform · Railway

To add e-signatures and clickwrap to a Railway app, run the `esigncomply` package in a Node.js service and keep the secret key in a sealed service variable. The service creates the session and confirms the record, and Railway Postgres keeps the pinned versions and the receipt for every replica. 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/railway)

`npm install esigncomply pg`

[Railway quickstart](https://esigncomply.com/docs/quickstart/railway)

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

Last updated November 26, 2026

Run locally for Railway before publishing

**Service**

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 confirmation can reach another replica.
  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 });
```

**railway.ts**

`.railway/railway.ts`

```ts
import { defineRailway, postgres, preserve, project, service } from "railway/iac";

export default defineRailway(() => {
  // The database that keeps the pinned versions and the receipt.
  const db = postgres("postgres");

  const web = service("web", {
    // Node.js directly, not "npm run start": the process then receives SIGTERM itself.
    start: "node server.js",
    preDeploy: "node migrate.js",
    healthcheck: "/health",
    env: {
      DATABASE_URL: db.env.DATABASE_URL,
      // Set these four on the service in Railway, in each environment, and seal the key.
      // preserve() keeps the value that is already there, so no secret is written in this file.
      ESIGNCOMPLY_API_KEY: preserve(),
      ESIGNCOMPLY_PROFILE_ID: preserve(),
      ESIGNCOMPLY_TERMS_ID: preserve(),
      ESIGNCOMPLY_PRIVACY_ID: preserve(),
    },
  });

  return project("esigncomply-quickstart", {
    resources: [web, db],
  });
});
```

**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 &&
    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
// Railway gives the service DATABASE_URL as a reference to the Postgres service: see .railway/railway.ts.
// Every replica opens its own pool on the same database, so they all see the same rows.
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 Railway

## How do you integrate Esign Comply with Railway?

On Railway the server half is one Node.js service. Railway injects `PORT`, calls `/health` before it sends traffic to a new deployment, and runs `migrate.js` as the pre-deploy command. A service can run several replicas with no sticky sessions, so the pinned versions go to Railway Postgres. `.railway/railway.ts` declares all of it.

Railway is an all-in-one intelligent cloud provider that makes it easy to provision infrastructure, develop locally, and deploy to the cloud.

Source: [Railway documentation, llms.txt](https://docs.railway.com/llms.txt), read on November 25, 2026.

[Railway quickstart](https://esigncomply.com/docs/quickstart/railway) · [All platforms](https://esigncomply.com/platforms)

Where each part lives on Railway

- **Service** · `server.js`
- **railway.ts** · `.railway/railway.ts`
- **Confirm** · `server.js`
- **Postgres store** · `store.js`

Run on 2026-11-26 in the image Railpack 0.43.1 built from this code (Node.js 26.13.1) with Railway's Postgres image (PostgreSQL 18.7), 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 was also started with Node.js 24.22.1 against PostgreSQL 17. The file .railway/railway.ts was started by railway config init (Railway CLI 5.75.0) and type-checked against railway 3.17.0. The Railway settings are from Railway's documentation as of 2026-11-25. Nothing has been deployed to Railway yet.

Three steps

## How does Esign Comply fit with Railway?

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

1. **A sealed service variable holds the key**

   Add `ESIGNCOMPLY_API_KEY` under Variables on the service, then seal it. Railway gives a sealed value to builds and deployments, and the value can no longer be read in the UI or through the API. The SDK reads the key from `process.env`. Source: [Railway documentation, Variables](https://docs.railway.com/variables), read on November 25, 2026.

2. **The service creates the session**

   `POST /api/ceremony` runs in your Node.js service. It calls `esc.sessions.create` and returns the client token. The same service serves the signup page, and the browser SDK records the ceremony from the signer's device.

3. **Railway Postgres keeps the receipt**

   The session route stores the pinned versions in a table in Railway Postgres, which the service 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. Source: [Railway documentation, PostgreSQL](https://docs.railway.com/databases/postgresql), read on November 25, 2026.

Railway setup

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

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

### Environment variables

Each Railway environment has its own values: `production` holds the live key and the live IDs, every other environment the test key and the test IDs. A change to a variable is staged and takes effect when you deploy it. Railway does not copy sealed variables into a PR environment.

Source: [Railway documentation, Variables](https://docs.railway.com/variables), read on November 25, 2026.

### The project file

Railway reads project configuration from `.railway/railway.ts`, and `railway config init` writes a starting file. The quickstart's file sets the start command, the healthcheck path and the pre-deploy command, and declares the database. Railway's documentation says `railway.json` and `railway.toml` are deprecated and stop being read on December 1, 2026.

Source: [Railway documentation, Infrastructure as Code](https://docs.railway.com/infrastructure-as-code), read on November 25, 2026.

### PR environments and test mode

A service in a PR environment answers on a host of its own under `up.railway.app`. A test key refuses a host it does not know: list the exact host under Domains in the Esign Comply dashboard as a test origin. Never list the shared suffix `up.railway.app`.

Source: [Railway documentation, Environments](https://docs.railway.com/environments), read on November 25, 2026.

### The registered domain and the webhook

Register your custom domain and verify it with one DNS record. A production service on its `up.railway.app` host verifies with a file at `/.well-known/esigncomply.txt`. For the `record.completed` webhook, add a route to the service and register its production URL under Webhooks in the Esign Comply dashboard.

Source: [Railway documentation, Working with domains](https://docs.railway.com/networking/domains/working-with-domains), read on November 25, 2026.

Read on November 25, 2026: [Railway documentation, Variables](https://docs.railway.com/variables), [Railway documentation, Environments](https://docs.railway.com/environments), [Railway documentation, Infrastructure as Code](https://docs.railway.com/infrastructure-as-code), [Railway documentation, Healthchecks](https://docs.railway.com/deployments/healthchecks), [Railway documentation, Pre-deploy command](https://docs.railway.com/deployments/pre-deploy-command), [Railway documentation, Scaling](https://docs.railway.com/deployments/scaling), [Railway documentation, PostgreSQL](https://docs.railway.com/databases/postgresql), [Railway documentation, Working with domains](https://docs.railway.com/networking/domains/working-with-domains), [Railway documentation, NodeJS SIGTERM Handling](https://docs.railway.com/deployments/troubleshooting/nodejs-sigterm-handling).

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Railway 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 Railway, 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 Railway

```
Add Esign Comply clickwrap to my app on Railway: 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/railway.md (the steps and the tested code for Railway)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Railway 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 service variable ESIGNCOMPLY_API_KEY, sealed, set in each Railway environment. Never commit it. Never print it. Railway does not copy sealed variables into PR environments.
- Listen on 0.0.0.0 on the port in PORT, which Railway injects. Start the service with "node server.js", not through npm, so the process receives SIGTERM.
- A service can run several replicas and Railway has no sticky sessions. Keep the pinned version IDs in Railway Postgres (DATABASE_URL), never in a variable of the process.
- Project configuration goes in .railway/railway.ts (Infrastructure as Code). Do not write railway.json or railway.toml: Railway has deprecated them.
- Expect live records only where RAILWAY_ENVIRONMENT_NAME is "production".
- 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 Railway?

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

- **Started through npm, the service never sees SIGTERM**

  Railpack's plan for the quickstart started it with `npm run start`. In the test, that container stopped with exit code 1 and `npm error signal SIGTERM`. Started with `node server.js`, the process received the signal itself, closed the database pool and exited with code 0. Set the start command in `.railway/railway.ts`.

  Source: [Railway documentation, NodeJS SIGTERM Handling](https://docs.railway.com/deployments/troubleshooting/nodejs-sigterm-handling), read on November 25, 2026.

- **Replicas share no memory, and Railway has no sticky sessions**

  Railway's documentation says public traffic is spread over the replicas of a service at random, and that sticky sessions are not supported. The request that confirms a record can reach a replica that never saw the session. In the test, a second container confirmed a record from the row in Postgres.

  Source: [Railway documentation, Scaling](https://docs.railway.com/deployments/scaling), read on November 25, 2026.

- **sslmode=require on DATABASE_URL refuses Railway's certificate**

  In a test against Railway's Postgres image, `pg` 8.23.1 treated `sslmode=require` as full verification and stopped with `self-signed certificate in certificate chain`. `DATABASE_URL` as Railway sets it connected, and so did `uselibpqcompat=true&sslmode=require`, with TLS.

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

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

- Quickstart

  **[Railway quickstart](https://esigncomply.com/docs/quickstart/railway)**

  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 Railway?

The same record on every stack and platform. Your Railway 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 Railway

### How does test mode work on Railway preview URLs?

A PR environment gets a host of its own under `up.railway.app`, which a test key refuses until you list that exact host under Domains as a test origin. Railway does not copy sealed variables into a PR environment, so set the test key on the service there. On `localhost` a test key works with no setup.

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

In Railway Postgres, beside the signer ID and the record ID. The confirm route writes both once the record is confirmed. The quickstart declares the database in `.railway/railway.ts` and uses one row for the pinned versions and the receipt.

### Why does the session route answer missing_api_key in a Railway PR environment?

Because the key is sealed, and Railway's documentation says sealed variables are not copied over when it creates PR environments. In the test, the image started without the key and the session route answered `502` with `missing_api_key`. Set the test key on the service in that environment.

### Should the project use railway.json or railway.ts?

`.railway/railway.ts`. Railway's documentation says `railway.json` and `railway.toml` are deprecated, stop being read on December 1, 2026, and cannot be used by new services. The quickstart's file was started by `railway config init` and type-checked against the `railway` package.

### Has this code run in a Railway deployment?

Not yet. The code ran in the image Railpack built, against Railway's own Postgres image, and the project file was type-checked against the `railway` package. The Railway settings come from Railway's documentation as of November 25, 2026. `railway config apply`, sealed variables, PR environments and replicas are proven only by a deployment.

### Other platforms

- [Render](https://esigncomply.com/render)
- [Fly.io](https://esigncomply.com/fly-io)
- [Google Cloud Run](https://esigncomply.com/google-cloud-run)

### Stacks used with Railway

- [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 Railway service. Leave the record to us.

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

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

Railway is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Railway is from Railway's documentation or from a test run, as marked, on November 25, 2026. `/railway.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.
