# Backend with TypeScript, PostgreSQL & Prisma: CI & Deployment URL: https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-deployment-bbba1ps7kip5 Published: 2020-09-17 Updated: 2026-11-11 Authors: Daniel Norman Series: Building a modern backend with TypeScript, PostgreSQL and Prisma Description: Set up CI/CD for a TypeScript, PostgreSQL, and Prisma ORM 7 backend with GitHub Actions, automated tests, and deployment to Prisma Compute. > Blog posts describe Prisma as it was on the date shown and are not kept current. Before implementing from a post, check the documentation index at https://www.prisma.io/docs/llms.txt and the changelog at https://www.prisma.io/changelog.md. > For an index of every published post, fetch https://www.prisma.io/blog/llms.txt. > **Update (July 2026):** This article was updated for Prisma ORM 7. Continuous integration still runs on GitHub Actions, but deployment now targets [Prisma Compute](https://www.prisma.io/compute), which runs your app next to your Prisma Postgres database, instead of Heroku. The app and its tests work with Prisma ORM 7 and Node.js 20 or later. > > **Update (November 2026):** The deploy section now uses [Prisma Composer](https://www.prisma.io/docs/composer) and `prisma deploy`, which replaced the beta-era `app deploy` command. The deploy tooling runs on the Prisma 8 CLI in its own `deploy/` folder, so the app itself stays on Prisma ORM 7. In this fourth and final part of the series, you'll configure continuous integration (CI) with GitHub Actions to run the tests, and deploy the backend to Prisma Compute. ## Introduction [#introduction] The goal of the series is to explore and demonstrate different patterns, problems, and architectures for a modern backend by solving a concrete problem: **a grading system for online courses.** ### What the series covers [#what-the-series-covers] | Topic | Part | | ------------------------------ | ----------------------------------------------------------------------------------------- | | Data Modeling | [Part 1](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-data-modeling-tsjs1ps7kip1) | | CRUD | [Part 1](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-data-modeling-tsjs1ps7kip1) | | Aggregations | [Part 1](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-data-modeling-tsjs1ps7kip1) | | REST API layer | [Part 2](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3) | | Validation | [Part 2](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3) | | Testing | [Part 2](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3) | | Passwordless Authentication | [Part 3](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-auth-mngp1ps7kip4) | | Authorization | [Part 3](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-auth-mngp1ps7kip4) | | Integration with external APIs | [Part 3](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-auth-mngp1ps7kip4) | | Continuous Integration | Part 4 (current) | | Deployment | Part 4 (current) | In the previous parts you built and secured a Hono REST API on top of a Prisma data model. In this article, you will set up GitHub Actions to run the tests on every push, then deploy the backend to [Prisma Compute](https://www.prisma.io/compute). Prisma Compute is TypeScript app hosting that runs your application on the same platform as your Prisma Postgres database. Because the app and database live together, you avoid the connection churn and cross-network latency that come with hosting them separately, and there's no separate database add-on to provision. > **Note:** Throughout the guide, you'll find various **checkpoints** that enable you to validate whether you performed the steps correctly. ## Prerequisites [#prerequisites] This article continues from [part 3](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-auth-mngp1ps7kip4). You'll need: * The `grading-app` project from the previous parts, pushed to a GitHub repository. * A free [Prisma Data Platform](https://console.prisma.io) account (the same one you used to create your Prisma Postgres database). * Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer. The app and its tests run on Node.js 20, but the deploy tooling needs the newer versions. * [Bun](https://bun.sh), which builds the file Compute runs. ## Continuous integration and continuous deployment [#continuous-integration-and-continuous-deployment] Continuous integration (CI) is the practice of integrating work into the main repository frequently, running an automated pipeline on every change to catch bugs early. Continuous deployment (CD) automates releasing those changes so they ship rapidly and consistently. While CI and CD have different responsibilities, they're often handled with the same tooling. Here you'll use GitHub Actions for CI (running the tests) and Prisma Compute's Git integration for CD (deploying on push). ### Continuous integration pipelines [#continuous-integration-pipelines] The main building block of CI is a pipeline: a set of steps that ensure no regressions are introduced. A pipeline might run tests, a linter, and the TypeScript compiler. If a step fails, the run stops and reports back to GitHub. When working with pull requests, the pipeline runs automatically for every PR. The [tests](https://www.prisma.io/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3) you wrote in part 2 and extended in part 3 send requests to the API's endpoints, and the handlers talk to the database. So the CI run needs a PostgreSQL database with the backend's schema for the duration of the tests. You'll configure GitHub Actions to start a throwaway Postgres database and apply the migrations before running the tests. > **Note:** CI is only as good as your tests. If coverage is low, passing tests can create a false sense of confidence. ### Defining a workflow with GitHub Actions [#defining-a-workflow-with-github-actions] GitHub Actions runs *workflows* defined in YAML files under `.github/workflows/`. A workflow has jobs, and each job has steps. Create `.github/workflows/grading-app.yml`: ```yaml name: grading-app on: [push, pull_request] jobs: test: runs-on: ubuntu-latest services: postgres: image: postgres:17 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: grading-app options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/grading-app steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: npm ci - run: npx prisma migrate deploy - run: npx prisma generate - run: npm test ``` The `test` job: 1. Checks out the repository. 2. Sets up Node.js 20. 3. Installs dependencies with `npm ci`. 4. Applies the committed migrations to the throwaway Postgres database with `prisma migrate deploy`. 5. Generates Prisma Client with `prisma generate`. 6. Runs the tests with `npm test`. The `services` block starts a PostgreSQL container that lives for the duration of the job, and `DATABASE_URL` points the app at it. `prisma migrate deploy` applies your existing migration files (unlike `migrate dev`, it never generates new ones), which is exactly what you want in CI and production. > **Note:** `on: [push, pull_request]` runs the pipeline for every push and every pull request. **Checkpoint:** Commit and push the workflow, then open the **Actions** tab of your GitHub repository. You should see the `grading-app` workflow run and the `test` job pass. ## Deploying to Prisma Compute [#deploying-to-prisma-compute] With CI in place, you'll deploy the backend to Prisma Compute using the Prisma CLI. Deploys to Compute are declared with [Prisma Composer](https://www.prisma.io/docs/composer): a small module names your services, and `prisma deploy` ships what it describes. Composer runs on the Prisma 8 CLI, while the app in this series uses Prisma ORM 7. To keep the two apart, the deploy declaration goes in its own `deploy/` folder with its own `package.json`. Your app code, schema, migrations, and root `prisma.config.ts` stay as they are. ### Set up the deploy folder [#set-up-the-deploy-folder] From the project root, create the folder and install the Composer packages and the Prisma CLI in it: ```sh mkdir deploy && cd deploy npm init -y npm pkg set type=module npm install @prisma/composer @prisma/composer-prisma-cloud npm install prisma --save-dev ``` The `prisma` package installed here is Prisma 8, the version npm installs by default. The root project keeps `prisma@7.9.1`, so `npx prisma` runs the Prisma 8 CLI inside `deploy/` and the Prisma ORM 7 CLI everywhere else. Commit `deploy/package-lock.json` along with the files you create below. ### Declare the app with Composer [#declare-the-app-with-composer] A `service.ts` declares the service and points at the file your build produces: ```ts title="deploy/service.ts" import node from "@prisma/composer/node"; import { compute } from "@prisma/composer-prisma-cloud"; export default compute({ name: "api", deps: {}, build: node({ module: import.meta.url, entry: "../dist/server.mjs" }), }); ``` The root module is the app. It provisions the service: ```ts title="deploy/module.ts" import { module } from "@prisma/composer"; import apiService from "./service.ts"; export default module("grading-app", ({ provision }) => { provision(apiService); }); ``` The deploy config is the `composer` section of a `prisma.config.ts` next to the module. This file is separate from the `prisma.config.ts` at the project root, which still configures Prisma ORM 7: ```ts title="deploy/prisma.config.ts" import { defineConfig as composer } from "@prisma/composer/config"; import { nodeBuild } from "@prisma/composer/node/control"; import { prismaCloud, prismaState } from "@prisma/composer-prisma-cloud/control"; import { definePrismaConfig } from "prisma/config"; export default definePrismaConfig({ composer: composer({ entry: "./module.ts", extensions: [prismaCloud({ region: "us-east-1" }), nodeBuild()], state: prismaState(), }), }); ``` The region is where the first deploy creates the project. A project that already exists keeps its region. The [deploy quickstart](https://www.prisma.io/docs/prisma-compute/deploy) explains each of these files in more depth. ### Add an entry point for Compute [#add-an-entry-point-for-compute] Compute runs your app on Bun. The server reads its port from `service.port()` and binds `0.0.0.0` so external traffic can reach it. Keep `src/index.ts` as it is for local development, and add a second entry that serves the same Hono app: ```ts title="src/server.ts" import app from "./app"; import service from "../deploy/service.ts"; Bun.serve({ port: service.port(), hostname: "0.0.0.0", fetch: app.fetch }); ``` ### Read the connection string from `POSTGRES_URL` [#read-the-connection-string-from-postgres_url] Compute reserves the name `DATABASE_URL` for databases that a deploy creates itself. This project connects to the database you already have, so on Compute `DATABASE_URL` holds a placeholder and you can't set it yourself. Store the connection string under another name, and have the app prefer it. In `src/lib/prisma.ts`, change the line that reads the URL: ```ts title="src/lib/prisma.ts" const databaseUrl = process.env.POSTGRES_URL ?? process.env.DATABASE_URL; ``` Locally and in CI, `POSTGRES_URL` isn't set, so the app keeps reading `DATABASE_URL`. ### Build and create the project [#build-and-create-the-project] `prisma deploy` ships what you built. It doesn't run the build. The build targets Bun, so [install Bun](https://bun.sh) if you haven't. From the project root, add a `build` script that generates Prisma Client and bundles the Compute entry into one file: ```sh npm pkg set scripts.build="prisma generate && bun build --target=bun src/server.ts --outfile dist/server.mjs" npm run build ``` The client is generated into `generated/prisma`, which isn't committed, so the script creates it before bundling. That matters later, when the deploy workflow runs the same script on a fresh checkout. Add `dist` to your `.gitignore`. Now switch to the `deploy/` folder, sign in, and run the first deploy: ```sh cd deploy npx prisma auth login npx prisma deploy ``` `auth login` opens the browser and stores a local session that later commands reuse. The deploy creates the `grading-app` project with its `api` service and prints the live URL. If your workspace already has a project named `grading-app` that this module didn't create, the deploy stops with `HostedStateBootstrapError`. In that case, change the name in `deploy/module.ts` to a unique one, deploy again, and use that name in place of `grading-app` in the commands below. The status route already responds, but the routes that query the database fail until the project has its environment variables. `deploy` also doesn't link your directory to the project it created, and the `project env` and `git` commands act on the linked project. Link it now: ```sh npx prisma project link grading-app ``` ### Setting environment variables [#setting-environment-variables] The backend needs three runtime variables: `POSTGRES_URL` (the connection string of the Prisma Postgres database you've used throughout the series), `JWT_SECRET` (used to sign JWTs), and `RESEND_API_KEY` (used to send login emails). > **Note:** If you used the Docker alternative in part 1, its `localhost` connection string won't work here. On Compute, `localhost` is the Compute instance, not your machine. Create a hosted database with `npx create-db` as described in part 1, apply your migrations to it by running `DATABASE_URL="postgres://..." npx prisma migrate deploy` from the project root, and use its connection string below. Still in `deploy/`, set the variables for the production environment: ```sh npx prisma project env add POSTGRES_URL="your-connection-string" --role production npx prisma project env add JWT_SECRET=your-secret --role production npx prisma project env add RESEND_API_KEY=your-key --role production ``` > **Note:** Generate a strong `JWT_SECRET` with: `node -e "console.log(require('crypto').randomBytes(64).toString('base64'))"`. Values resolve at deploy time, so deploy again to give the running service its variables: ```sh npx prisma deploy ``` Your app connects to the same Prisma Postgres database you've used throughout the series, so there's no separate database to provision and your data is already there. **Checkpoint:** When the deploy finishes, the CLI prints your live URL. Open it and confirm the status route responds: ```sh npx prisma service open grading-app.api ``` Visiting the root should return `{"up":true}`. The login flow at the end of this article confirms that the app reaches the database. ### Deploying automatically on every push [#deploying-automatically-on-every-push] To make deployment continuous, connect the repository to the project and add a deploy workflow. Connect first, from `deploy/`: ```sh npx prisma git connect ``` The connection lets the repository's GitHub Actions runs sign in to your workspace, so the workflow needs no secrets. It doesn't deploy anything by itself. Deploys come from a workflow that runs [prisma/cloud-deploy-action](https://github.com/prisma/cloud-deploy-action). Create `.github/workflows/prisma-deploy.yml`: ```yaml title=".github/workflows/prisma-deploy.yml" name: prisma-deploy on: push: concurrency: group: prisma-deploy-${{ github.ref }} cancel-in-progress: false permissions: contents: read id-token: write jobs: deploy: if: github.ref_type == 'branch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 22 - uses: oven-sh/setup-bun@v2 - run: npm ci - uses: prisma/cloud-deploy-action@v1 with: working-directory: deploy build-command: npm --prefix .. run build ``` The `npm ci` step installs the app's dependencies at the root. The action then works inside `deploy/`: it installs the Composer packages, runs the root `build` script, and runs the same `prisma deploy` you ran by hand. Once the workflow is committed, every push to your default branch deploys to production, and every other branch gets its own preview with its own URL. Previews read preview-scoped variables, so set those with `--role preview` and point `POSTGRES_URL` at a database that isn't your production one. [Deploy on push](https://www.prisma.io/docs/compute/deploy-on-push) covers previews in detail. Your `grading-app` workflow stays focused on running the tests. To stream the deployed app's logs while you debug: ```sh npx prisma service logs grading-app.api --follow ``` ## Testing the login flow in production [#testing-the-login-flow-in-production] With the app deployed, exercise the passwordless login flow from part 3 against the live URL. First, start login: ```sh curl -X POST -H "Content-Type: application/json" \ -d '{"email":"you@example.com"}' \ https://YOUR_APP_URL/login ``` Because `RESEND_API_KEY` is set in production, the token is emailed rather than logged. Check your inbox for the eight-digit token, then exchange it for a JWT: ```sh curl -i -X POST -H "Content-Type: application/json" \ -d '{"email":"you@example.com", "emailToken":"12345678"}' \ https://YOUR_APP_URL/authenticate ``` **Checkpoint:** The response has a `200` status and an `Authorization` header containing the JWT: ``` Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbklkIjo4fQ.ea2lBPMJ6mrPkwEHCgeIFqqQfkQ2uMQ4hL-GCuwtBAE ``` ## Summary [#summary] Your backend is now tested on every push and deployed to Prisma Compute. Well done, and congratulations on finishing the series. You configured a GitHub Actions workflow that spins up a throwaway PostgreSQL database, applies your migrations, and runs the tests, then deployed the app to Prisma Compute with the Prisma CLI and wired up deploy-on-push with the Git integration. Because the app runs next to your Prisma Postgres database, you skipped the separate database add-on and the connection-churn concerns of hosting them apart. Over the four parts, you designed a data model, built a REST API with Hono, secured it with passwordless authentication and authorization, and shipped it with CI/CD, using [Prisma Client](https://www.prisma.io/docs/orm/v7/prisma-client) and Prisma Migrate throughout, with the schema as the single source of truth. If AI agents are part of your workflow, the [Prisma MCP server](https://www.prisma.io/docs/ai/tools/mcp-server) lets them create and manage Prisma Postgres databases as they need them. This series teaches Prisma ORM 7, which remains supported, with its docs at [prisma.io/docs/orm/v7](https://www.prisma.io/docs/orm/v7). To see where Prisma ORM is heading for AI-assisted development, read [The Next Evolution of Prisma ORM](https://www.prisma.io/blog/the-next-evolution-of-prisma-orm). Prisma 8 is the agent-native evolution of the ORM and the version npm installs by default. It builds on the same schema-as-contract idea you relied on across this series, with structured, type-safe output that humans and coding agents can build on safely, and you can adopt it incrementally alongside an existing project. The [performance benchmark](https://www.prisma.io/blog/prisma-next-performance-benchmark) covers what the rewrite means for throughput and client size.