> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reliantlabs.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy Express with Reliant Forge

> Deploy a Node.js Express API with Postgres from its own Dockerfile: Forge adopts it in place, runs npm run migrate or prisma migrate deploy before every rollout, and ships it to Reliant hosting.

You will take an Express API with a Dockerfile, a `docker-compose.yml` that runs Postgres, and a `migrate` script, and deploy it to [Reliant hosting](https://docs.reliantlabs.io/hosting/overview.md) with a managed Postgres. Forge reads the Dockerfile, the compose file and `package.json` and writes its declarations beside them; no JavaScript changes. This guide was run on a minimal notes API (`express` + `pg`) at Forge `v1.10.1-0.20261123064811-54313eead62f`.

## Before you begin

* Docker, and the app in a git repository with a root `Dockerfile` that builds on its own.
* Forge: `reliant forge` inside Reliant, or `npx -y @reliantlabs/forge@latest` anywhere else.
* For a deploy that lasts, a Reliant account with [app hosting billing](https://docs.reliantlabs.io/hosting/overview.md#billing). With no account you can publish a 72-hour preview (step 5).

## What the Dockerfile must do

A deploy runs `docker build` on the Dockerfile and its context alone, so install and build inside it: a Dockerfile that `COPY`s a `dist/` or `node_modules` from your machine fails there. The detector takes the port from the compose service's published port, else `EXPOSE`, else `ENV PORT`, and sets `PORT` in the container. Listen on it, on all interfaces:

```js server.js (excerpt) theme={null}
const port = Number(process.env.PORT || 3000);
app.listen(port, "0.0.0.0", () => console.log(`listening on ${port}`));
```

```dockerfile Dockerfile theme={null}
FROM node:22-slim
WORKDIR /app
COPY package*.json ./
RUN npm install --omit=dev
COPY . .
USER node
ENV PORT=3000
EXPOSE 3000
CMD ["node", "server.js"]
```

`USER node` runs as the non-root user the official image ships. Start with `node`, not `npm start`: npm doesn't forward SIGTERM, so every rollout waits out the grace period. Put `node_modules`, `deploy`, `.forge` and `secrets` in `.dockerignore`.

## Postgres and migrations

Read `DATABASE_URL` (`new Pool({ connectionString: process.env.DATABASE_URL })`). Hosting fills it from a managed Postgres per environment; dev keeps the compose `db` service. The detector makes a `migrate` job, run from the app's image before every rollout, from the first of: a compose service that migrates, a `migrate` script in `package.json`, or prisma, knex, sequelize-cli or drizzle-kit in the dependencies. With Prisma the command is `npx prisma migrate deploy`; keep `prisma` (and the `prisma/` directory) in the final image, not in devDependencies you prune, because the job runs that image.

**1. Preview what Forge would write**

```bash terminal theme={null}
reliant forge project new --in-place --kind app --dry-run
```

```text Output (trimmed) theme={null}
Detected:
  - Postgres: compose service "db" (postgres:16) → a managed Postgres on staging and prod; dev keeps the compose service
  - workload api (service): compose service "api", builds Dockerfile, port 3000, reads DATABASE_URL
  - migrations: npm run migrate (package.json script "migrate") → job migrate from api's image, before every rollout
```

**2. Adopt the app and check it**

```bash terminal theme={null}
reliant forge project new --in-place --kind app --name notes-api
git add -A && git commit -m "Adopt with forge"
docker build .
reliant forge env render prod
reliant forge lint
```

```text Output (trimmed) theme={null}
hosted (published to the control plane, not applied):
  migrate (job)
  api (service)
  notes (database)
✅ 13 gating linter(s) passed; 2 skipped (contract linter, migration safety lint)
```

`deploy/kcl/workloads.k` now holds `api` (port 3000, a TCP probe) and `migrate` (`command = ["npm", "run", "migrate"]  # check: package.json script "migrate"`). Read every `# check:` line. `reliant forge env up dev` runs your compose file, as `docker compose up` did.

**3. Set secrets**

Every compose variable that looks like a credential (`SESSION_SECRET: ${SESSION_SECRET}`) is a `forge.ManagedSecret` on staging and prod. Set each from stdin:

```bash terminal theme={null}
openssl rand -hex 32 | reliant forge env secret set --env prod SESSION_SECRET
```

Then fix the fallbacks: `process.env.SESSION_SECRET || "dev"` runs prod with a public value if the secret is never set. Throw at startup when it is missing.

**4. Deploy**

Signed in:

```bash terminal theme={null}
reliant forge env deploy prod --yes
```

It builds the image, cuts a release, runs `migrate`, then rolls out `api`. Without app hosting billing it is queued, exits **7** and prints the billing link. The default size is 250m CPU and 1 GiB per workload.

With no account, adopt with `--claimable` so prod fits the anonymous plan, preview, then publish:

```bash terminal theme={null}
npx -y @reliantlabs/forge@latest project new --in-place --kind app --claimable
npx -y @reliantlabs/forge@latest env deploy prod --claimable --plan-only
```

```text Output (trimmed) theme={null}
  claimable limits: 125m / 128 MiB per workload, Postgres storage 256 MiB of data (1 GiB volume)
  ✓ fits the claimable plan: one service (at most 125m / 128 MiB) with its migration job, one database, one static site
  ! no outbound internet until claimed: the service serves requests and uses its database, but calls out of it fail (payments, LLMs, webhooks, outside DNS)
  ✓ the platform is taking anonymous deploys of this shape right now
```

`--plan-only` with `--claimable` uses no identity and creates nothing. `npx -y @reliantlabs/forge@latest env deploy prod --claimable` then publishes and prints the URL and a claim link, live for 72 hours. An unclaimed deploy gets **no secret values** (`--claimable` adoption says prod "delivers none of SESSION\_SECRET until it is claimed") and no outbound internet, so code that needs either must degrade, not crash. The test app idled at about 28 MiB, well inside 128 MiB. Inside Reliant you are signed in and `--claimable` is refused (exit 1). See [Deploy without an account](https://docs.reliantlabs.io/forge/deploy-without-an-account.md).

**5. Verify**

```bash terminal theme={null}
reliant forge env status prod
curl -s -X POST -H 'Content-Type: application/json' -d '{"body":"hi"}' https://<your-url>/notes
reliant forge obs check prod --wait --json
```

Exit codes: **0** proven good, **1** regressed (run its `suggested[]` commands), **2** not proven, **8** the wait ran out (check later). An app with no OpenTelemetry SDK gets 2, `reason_code: no_request_telemetry`: "not proven good", never "passed". Add `@opentelemetry/auto-instrumentations-node` ([guide](https://docs.reliantlabs.io/guides/observability/send-opentelemetry-from-any-app.md)) to get real verdicts.

## Express gotchas

* **`trust proxy`.** TLS ends at the ingress, so set `app.set("trust proxy", 1)` before relying on `req.secure`, `req.ip` or `secure` cookies.
* **TypeScript.** Compile in a build stage (`npm ci && npm run build`) and copy `dist/` into the runtime stage; never ship a `dist/` built on your laptop.
* **Health.** Replace the TCP probe with `tiers.Probes {readinessPath = "/healthz"}` once `/healthz` checks the pool.

## Troubleshooting

> [accordion] this content was refused by the platform's safety scan
>
> An unclaimed deploy is scanned before it goes live, and `reason: claimable_content_refused` doesn't say what was found. Our test of this exact app (`node:22-slim`, `express`, `pg`) was refused at this point: the image was built and pushed, nothing was published, and `env status prod --claimable` showed `published: false`. Don't hand out the claim link in that state. Deploy signed in instead.

> [accordion] container …-migrate-1 exited (0) … service did not become healthy
>
> A compose `migrate` service under a plain `depends_on`. Use `depends_on: {migrate: {condition: service_completed_successfully}}`.

See also: [Bring an existing app](https://docs.reliantlabs.io/guides/forge/bring-existing-app-any-language.md), [Managed Postgres](https://docs.reliantlabs.io/hosting/managed-postgres.md), [Secrets](https://docs.reliantlabs.io/hosting/secrets.md), [Hosting limits](https://docs.reliantlabs.io/hosting/limits.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.