# Deploy an existing app on Prisma Compute (/docs/guides/compute/deploy-existing-app) > For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL. Use when a Node.js server already on Prisma 8 with PostgreSQL should deploy on Prisma Compute from GitHub, with a Prisma Postgres database for each branch Location: Guides > Build on Compute > Deploy an existing app on Prisma Compute > [!NOTE] > Not for an app on Prisma ORM 6 or 7, or for a new app > > Prisma Compute runs only Prisma 8. To upgrade an app on Prisma ORM 6 or 7 first, start at [Upgrade to Prisma 8](https://www.prisma.io/docs/guides/upgrade-prisma-orm). To start a new app on Compute, follow [Getting started](https://www.prisma.io/docs/compute/getting-started). This guide takes an Express, Fastify, Hono or other Node.js server that already runs Prisma 8 on PostgreSQL and deploys it on [Prisma Compute](https://www.prisma.io/docs/compute) from its GitHub repository. At the end, every push deploys the app: the default branch to production, and every other branch to a preview with its own Prisma Postgres database. The examples continue the feedback board from [Prisma ORM 6 or 7 to 8 (PostgreSQL)](https://www.prisma.io/docs/guides/upgrade-prisma-orm/postgresql): Express 4, EJS views, compiled with `tsc` to `dist/` and started with `node dist/server.js`. If you use a coding agent, the `prisma-compute` skill follows this guide: #### bun ```bash bunx skills add prisma/skills --skill prisma-compute ``` #### pnpm ```bash pnpm dlx skills add prisma/skills --skill prisma-compute ``` #### yarn ```bash yarn dlx skills add prisma/skills --skill prisma-compute ``` #### npm ```bash npx skills add prisma/skills --skill prisma-compute ``` ## Prerequisites [#prerequisites] * **Node.js 24.11 or newer.** `prisma dev`, which runs the app locally the way Compute runs it, refuses older versions. * **A Prisma 8 app on PostgreSQL** at `prisma@8.0.0-rc.27` and `@prisma/orm-postgres@8.0.0-rc.20`, with its client created by `postgres({ contract, url })`, the emitted contract in `src/prisma/`, and its migrations in `migrations/app/`. These are the versions the Console's setup works with today; newer ones do not yet deploy. * **The app in a GitHub repository**, with a committed lockfile, and a [Prisma Console](https://console.prisma.io/?utm_source=docs\&utm_medium=content\&utm_content=guides) workspace you can connect it to. ## How the app changes on Compute [#how-the-app-changes-on-compute] On Prisma Compute, the app does not read `DATABASE_URL`. The deploy creates a Prisma Postgres database for each branch, applies `migrations/app/` to it, and hands the app a client connected to it. `DATABASE_URL` is a reserved variable that holds the placeholder `-`, so an app that keeps reading it deploys and then fails every query with `P1001` and `host: "base"`. Two more changes follow from that. Compute ships only what your build writes to `dist/`, so the files the server reads at runtime have to be in it. And because the client comes from [Prisma Composer](https://www.prisma.io/docs/composer), the part of Compute that runs your app, `npm start` stops working: locally, the app runs under `prisma dev` instead. ## 1. Connect the repository in the Console [#1-connect-the-repository-in-the-console] Push your work, then in the [Console](https://console.prisma.io/?utm_source=docs\&utm_medium=content\&utm_content=guides) create a project and connect the repository to it. [GitHub](https://www.prisma.io/docs/compute/github) describes the connection. The project's region is set when it is created and cannot change later, so pick the one nearest your users. To set up deploys without the Console, skip to [Without the Console](#without-the-console). The Console opens a pull request, **Set up Prisma Cloud deploys**, on a branch named `prisma-cloud/setup`. It adds: * `.github/workflows/prisma-deploy.yml`, which deploys every push: the default branch to production, and every other branch to its own preview. * `module.mjs`, which declares the app and its Prisma Postgres database for Composer. * `service.mjs`, which declares your server as a service with `deps: { db: postgres(dataContract(contractJson)) }`, the database it needs. * A `composer` section in `prisma.config.ts`, and the Composer packages in `package.json`. The setup keeps the `prisma` and `@prisma/orm-postgres` versions your `package.json` declares. Because the workflow runs on every push, the setup branch deploys as a preview. Make the changes below on that branch, and merge the pull request only after its preview works, because merging deploys production. ## 2. Move the service declaration into your build [#2-move-the-service-declaration-into-your-build] A Compute service runs the files your build produces, here `dist/`, and nothing outside them. Your server code imports the service declaration to get its database, so the declaration has to be part of the build. Check out the setup branch, then move `service.mjs` into `src/` as a TypeScript ES module: ```bash git switch prisma-cloud/setup git rm service.mjs ``` ```typescript title="src/service.mts" import node from "@prisma/composer/node"; import { compute } from "@prisma/composer-prisma-cloud"; import { postgres, dataContract } from "@prisma/composer-prisma-cloud/orm"; import type { Contract } from "./prisma/contract.js"; import contractJson from "./prisma/contract.json" with { type: "json" }; export const data = dataContract(contractJson); export default compute({ name: "feedback-board", deps: { db: postgres(data) }, build: node({ module: import.meta.url, dir: ".", entry: "server.js", dependencies: "external" }), }); ``` Keep the `name` the setup wrote. `tsc` compiles this file to `dist/service.mjs`, so `dir: "."` is `dist/` and `entry` is the file in it that starts your server, the one `npm start` runs. Check it, because the setup guesses the entry from your repository and can get it wrong. `dependencies: "external"` ships the packages in `node_modules` that the entry imports, since `tsc` does not bundle them. `dataContract(...)` gives the client the types from `contract.d.ts`. In `module.mjs`, import the compiled service instead of the deleted file: ```javascript title="module.mjs" import feedbackBoardService from "./service.mjs"; // [!code --] import feedbackBoardService from "./dist/service.mjs"; // [!code ++] ``` The deploy workflow runs `npm run build` before it reads `module.mjs`, so `dist/service.mjs` exists by then. ## 3. Take the client from the service [#3-take-the-client-from-the-service] Change `src/db.ts` to use the client Composer connects to the branch's database: #### Prisma Compute ```typescript title="src/db.ts" import service from "./service.mjs"; export const db = service.load().db.client; ``` #### Before ```typescript title="src/db.ts" import "dotenv/config"; import postgres from "@prisma/orm-postgres/runtime"; import { contractFromJson } from "@prisma/orm-postgres/static"; import type { Contract } from "./prisma/contract.d"; import contractJson from "./prisma/contract.json"; export const db = postgres({ contract: contractFromJson(contractJson), url: process.env["DATABASE_URL"]!, }); ``` `db.client` has the same type as the client you had, so the rest of your code does not change. `service.load().db` also has `url`, the raw connection string, for a library that needs one. `src/db.ts` stays CommonJS and loads the ES module through `require`, which Node.js 22.12 and newer support. Have the server listen on `service.port()` and `"0.0.0.0"` instead of `process.env.PORT`. Outside a Composer run, `service.load()` throws `missing required config param "url"`, so `npm start`, a `tsx` dev script and a `Procfile` stop working. Run the app locally under `prisma dev`, which starts a local Prisma Postgres, applies `migrations/app/` to it, and runs the service the way Compute does: #### bun ```bash bun run build bunx prisma dev module.mjs ``` #### pnpm ```bash pnpm run build pnpm prisma dev module.mjs ``` #### yarn ```bash yarn build yarn prisma dev module.mjs ``` #### npm ```bash npm run build npx prisma dev module.mjs ``` **Expected result:** `dev: ready` and the service's local URL, such as `feedbackboard: http://localhost:3000`. The local database starts empty. Make `npm run build && npx prisma dev module.mjs` your `dev` script. A seed script must not import `src/db.ts`: keep its own `postgres({ contract, url })` client, and run it against the local database with `DATABASE_URL="$(npx prisma dev url database)" npx tsx prisma/seed.ts`. ## 4. Ship files the server reads at runtime [#4-ship-files-the-server-reads-at-runtime] Only `dist/` reaches Compute, so if your server reads other files at runtime, such as EJS views in `views/` or static files in `public/`, copy them into `dist/` in the build, and read them from next to the compiled code: ```json title="package.json (excerpt)" { "scripts": { "build": "tsc", // [!code --] "build": "tsc && cp -R views public dist/" // [!code ++] } } ``` ```typescript title="src/server.ts (excerpt)" app.set("views", path.join(__dirname, "..", "views")); // [!code --] app.set("views", path.join(__dirname, "views")); // [!code ++] app.use(express.static(path.join(__dirname, "..", "public"))); // [!code --] app.use(express.static(path.join(__dirname, "public"))); // [!code ++] ``` Without this, the app starts and every page it renders fails with `Failed to lookup view`. ## 5. Set your other environment variables [#5-set-your-other-environment-variables] Compute sets the database and the port. Pass every other variable your app reads to the service as a [service input](https://www.prisma.io/docs/composer/service-input), which reads the same value on Compute and under `prisma dev`. Declare the input in the service: ```typescript title="src/service.mts (excerpt)" import { type } from "arktype"; import { secretString } from "@prisma/composer/arktype"; export default compute({ name: "feedback-board", deps: { db: postgres(data) }, input: type({ sessionSecret: secretString() }), // [!code ++] build: node({ module: import.meta.url, dir: ".", entry: "server.js", dependencies: "external" }), }); ``` Add `arktype` as a direct dependency, at the version `@prisma/composer` already uses, which `npm ls arktype` prints. Then fill the input from a project environment variable where `module.mjs` provisions the service, and read it in the server: ```javascript title="module.mjs (excerpt)" import { envSecret } from "@prisma/composer-prisma-cloud"; provision(feedbackBoardService, { deps: { db: database }, input: { sessionSecret: envSecret("SESSION_SECRET") }, // [!code ++] }); ``` ```typescript title="src/server.ts (excerpt)" const SESSION_SECRET = process.env.SESSION_SECRET!; // [!code --] const SESSION_SECRET = service.input().sessionSecret.expose(); // [!code ++] ``` Set each value for production and for previews. `read -rs` asks for the value without showing it, and given only the variable's name, `project env add` reads the value from your environment, so the secret stays off the command line and out of your shell history: ```bash read -rs SESSION_SECRET && export SESSION_SECRET # type the production value, then press Enter npx prisma project env add SESSION_SECRET --role production read -rs SESSION_SECRET && export SESSION_SECRET # type the preview value, then press Enter npx prisma project env add SESSION_SECRET --role preview unset SESSION_SECRET ``` Run these from a directory linked to the project, or add `--project `. Set them before you push, and redeploy after you change one. [Environment variables](https://www.prisma.io/docs/compute/environment-variables) covers scopes and branch overrides. ## 6. Push and check the preview [#6-push-and-check-the-preview] ```bash git add -A git commit -m "Deploy on Prisma Compute" git push ``` The push runs the deploy workflow for the setup branch. Find the preview's URL: #### bun ```bash bunx prisma service list --branch prisma-cloud/setup ``` #### pnpm ```bash pnpm prisma service list --branch prisma-cloud/setup ``` #### yarn ```bash yarn prisma service list --branch prisma-cloud/setup ``` #### npm ```bash npx prisma service list --branch prisma-cloud/setup ``` **Expected result:** the request you use as a health check succeeds against that URL, for example `curl https:///healthz` returns `{"ok":true}`, and pages that read and write the database work. The preview database starts empty, with your schema from `migrations/app/` and no data. When the preview works, merge the pull request. The merge deploys production the same way, with its own database. ## Without the Console [#without-the-console] To set up deploys yourself, write the files the setup pull request adds, make the changes from steps 2 to 5, deploy once from your machine, and then connect the repository. Start with the Composer packages, at the version that matches `@prisma/orm-postgres@8.0.0-rc.20`, because the latest Composer release does not work with it: #### bun ```bash bun add --exact @prisma/composer@0.34.0 @prisma/composer-prisma-cloud@0.34.0 ``` #### pnpm ```bash pnpm add --save-exact @prisma/composer@0.34.0 @prisma/composer-prisma-cloud@0.34.0 ``` #### yarn ```bash yarn add --exact @prisma/composer@0.34.0 @prisma/composer-prisma-cloud@0.34.0 ``` #### npm ```bash npm install --save-exact @prisma/composer@0.34.0 @prisma/composer-prisma-cloud@0.34.0 ``` Add a `composer` section to `prisma.config.ts`, with the region for the project the first deploy creates. Keep the `orm` section you have; the one below is from the upgrade guide: ```typescript title="prisma.config.ts" import "dotenv/config"; import { definePrismaConfig } from "prisma/config"; import { defineConfig, prisma7Schema } from "@prisma/orm-postgres/config"; import { defineConfig as composer } from "@prisma/composer/config"; // [!code ++] import { nodeBuild } from "@prisma/composer/node/control"; // [!code ++] import { prismaCloud, prismaState } from "@prisma/composer-prisma-cloud/control"; // [!code ++] export default definePrismaConfig({ orm: defineConfig({ contract: prisma7Schema("prisma/schema.prisma"), output: "src/prisma", db: { connection: process.env["DATABASE_URL"], }, }), composer: composer({ // [!code ++] extensions: [prismaCloud({ region: "eu-central-1" }), nodeBuild()], // [!code ++] state: prismaState(), // [!code ++] }), // [!code ++] }); ``` The region cannot change after the first deploy creates the project. [Limitations](https://www.prisma.io/docs/compute/limitations#runtime) lists the ones you can choose. Declare the app and its database in `module.mjs`, from the same contract the service in step 2 exports: ```javascript title="module.mjs" import { module } from "@prisma/composer"; import { postgres } from "@prisma/composer-prisma-cloud/orm"; import feedbackBoardService, { data } from "./dist/service.mjs"; export default module("feedback-board", ({ provision }) => { const database = provision(postgres({ name: "database", contract: data, config: "prisma.config.ts" })); provision(feedbackBoardService, { deps: { db: database } }); }); ``` Composer writes local state to `.prisma/`, `.prisma-composer/` and `.alchemy/`, so add those folders to `.gitignore`. Then make the changes from steps 2 to 5, and deploy production once from your machine. The deploy creates the project, and the commands after it link this directory to the project and connect the repository: #### bun ```bash bun run build bunx prisma deploy --entry module.mjs bunx prisma project link feedback-board bunx prisma git connect ``` #### pnpm ```bash pnpm run build pnpm prisma deploy --entry module.mjs pnpm prisma project link feedback-board pnpm prisma git connect ``` #### yarn ```bash yarn build yarn prisma deploy --entry module.mjs yarn prisma project link feedback-board yarn prisma git connect ``` #### npm ```bash npm run build npx prisma deploy --entry module.mjs npx prisma project link feedback-board npx prisma git connect ``` `git connect` opens the browser so you can install the Prisma GitHub app, and it does not add a deploy workflow. Add the workflow from [Deploy on push](https://www.prisma.io/docs/compute/deploy-on-push#4-add-the-deploy-workflow), with `module: module.mjs` in the action's inputs, because the action looks for `module.ts` by default: ```yaml title=".github/workflows/prisma-deploy.yml (excerpt)" - uses: prisma/cloud-deploy-action@v1 with: build-command: npm run build module: module.mjs ``` Push a branch other than the default one, and check its preview as in step 6. ## Next steps [#next-steps] * [Deploy on push](https://www.prisma.io/docs/compute/deploy-on-push): how previews, production and branch cleanup work once the workflow is in place. * [Databases in Prisma Composer](https://www.prisma.io/docs/composer/databases): the `postgres()` database, its client, and how the deploy migrates it. ## Related pages - [`Build a marketing site with Astro`](https://www.prisma.io/docs/guides/compute/astro-marketing-site): Build a static marketing site with Astro, serve it from a Node server, and deploy it to Prisma Compute with Prisma Composer.