Fly.io
Learn how to deploy applications using Prisma Postgres to Fly.io
Fly.io is a cloud application platform that lets you deploy full-stack applications globally. This guide shows you how to deploy a Node.js application using Prisma Postgres to Fly.io.
Prerequisites
Section titled “Prerequisites”- A Fly.io account
- The Fly CLI installed
- An existing application using Prisma Postgres (see Quickstart)
Deploy your application
Section titled “Deploy your application”1. Generate Prisma Client in postinstall
Section titled “1. Generate Prisma Client in postinstall”Ensure your package.json includes a postinstall script to generate Prisma Client during deployment:
{ // ... "scripts": { // ... "postinstall": "prisma generate" }}2. Launch your app with Fly.io
Section titled “2. Launch your app with Fly.io”From your project directory, run:
fly launchFollow the prompts to configure your application. Fly.io will auto-detect your Node.js application and create the necessary configuration.
3. Set your database connection string
Section titled “3. Set your database connection string”Add your Prisma Postgres DATABASE_URL as a secret in Fly.io:
fly secrets set DATABASE_URL="your-prisma-postgres-connection-string"4. Deploy
Section titled “4. Deploy”If not already deployed during fly launch, deploy your application:
fly deployOnce the deployment completes, you'll see a success message with your app's URL:
🎉 SUCCESS! Your app is live and ready to use! 🎉
Visit: https://your-app-name.fly.dev/Additional considerations
Section titled “Additional considerations”Ensure your project uses the correct environment variable
Section titled “Ensure your project uses the correct environment variable”Ensure that the data source in your prisma.config.ts file is configured to use the DATABASE_URL environment variable:
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
datasource: {
url: env("DATABASE_URL"),
},
schema: "prisma/schema.prisma",
});Running migrations in production
Section titled “Running migrations in production”To run migrations on your deployed Fly.io app, you can use:
fly ssh console -C "npx prisma migrate deploy"Or add a release command to your fly.toml:
[deploy]
release_command = "npx prisma migrate deploy"Scaling and regions
Section titled “Scaling and regions”Fly.io lets you scale and place your application in multiple regions. To reduce latency, deploy your app in a region close to your Prisma Postgres database region.
fly scale count 2 --region iadTroubleshooting
Section titled “Troubleshooting”Prisma schema not found or Client not generated correctly
Section titled “Prisma schema not found or Client not generated correctly”If you're using a custom Dockerfile and your build fails because the Prisma Client cannot be found, it's likely due to one of two reasons:
- Order of operations:
npm install(which runspostinstall) runs before the schema is copied. - Incorrect copy path: The schema is copied to the root instead of the
prismafolder.
Solution: In your Dockerfile, copy the prisma/ directory to ./prisma before running npm install:
# ❌ Wrong order or path
COPY package*.json ./
COPY prisma . # Copies contents to root (wrong structure)
RUN npm install # postinstall runs but might fail or generate in wrong place
# ✅ Correct order and path
COPY package*.json ./
COPY prisma ./prisma # Copies to ./prisma folder (preserves structure)
RUN npm install # postinstall finds schema in expected location
COPY . .