Stop 15 · DevOps & DeploymentTopics · 4/8

Deploying the Backend

Part of the Full Stack Developer Roadmap

In short

A frontend is a set of files; a backend is a running process. Deploying it means keeping a Node server alive, connected to a real database, with health checks watching it.

Shipping your Express/Node API to production — to a platform like Railway, Render, or a containerized deployment, with a real database connected.

The blob character rolls up the shutter of a roadside dhaba with a stove already burning inside.

Think of it like this

Opening a highway dhaba

A dhaba isn't printed and shipped like a newspaper. The stove must stay lit all day, the water tank must be connected, and someone must relight the fire if it goes out. Your API is the dhaba: a live process, plugged into a database, watched and restarted by the platform.

Watch it happen

What a backend deploy does

Push
Build
Migrate
Start
Health
Traffic

1/6You push to main. A platform like Railway, Render or Fly.io starts a new deploy.

The big ideas

What you need to know

A long-running process

Your Express app must stay up, so it needs a platform that runs and restarts processes, not just a file host.

Secrets in env vars

DATABASE_URL, JWT secrets and API keys go in the platform's settings, never in the repo.

Health checks

A /healthz route that touches the database lets the platform hold back a broken deploy.

CORS for the real frontend

Allow your deployed frontend's origin, like https://myshop.in. Not localhost, and not every origin.

See it in code

Walk through the code

ts
1import express from "express";2import { pool } from "./db";3 4const app = express();5app.get("/healthz", async (_req, res) => {6  await pool.query("SELECT 1");7  res.json({ ok: true });8});9 10const port = Number(process.env.PORT ?? 4000);11const server = app.listen(port, "0.0.0.0", () => console.log(`API listening on ${port}`));12 13process.on("SIGTERM", () => {14  server.close(() => pool.end().then(() => process.exit(0)));15});

1/3The health route checks the database too, so 'up but can't reach Postgres' counts as unhealthy.

With Express 5, an error thrown inside the async health route becomes a 500 automatically, which tells the platform this version isn't healthy.

Save yourself the pain

Common mistakes

Oops

Hardcoding app.listen(4000) on a platform that assigns its own port.

Do this instead

Read process.env.PORT. Many hosts route traffic only to the port they set there.

Oops

Running migrations by hand from your laptop against production.

Do this instead

Run them in the deploy's release step, so the code and the schema change together.

Your mission

Put your API online

~40 min

Quick check

Why does a backend need a health check endpoint like /healthz?

Go deeper

  1. 1Deploy your backend to Railway or Render, connecting a managed database.
  2. 2Set production environment variables through the platform's dashboard, not in code.
  3. 3Confirm your deployed frontend can successfully reach your deployed backend, CORS included.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge