---
title: "Deploy Next.js + Prisma + PostgreSQL Starter"
description: "Deploy a Next.js app with Prisma ORM and PostgreSQL in one click."
category: "Starters"
url: https://railway.com/deploy/nextjs-prisma-postgres
---

# Deploy Next.js + Prisma + PostgreSQL Starter

Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.

**[Deploy Next.js + Prisma + PostgreSQL Starter on Railway](https://railway.com/template/nextjs-prisma-postgres)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/nextjs-prisma-postgres/manifest.json

- **Creator:** blueorange
- **Category:** Starters

## Template content

### nextjs https://devicons.railway.app/NextJS%20Prisma?variant=light

- **Source:** https://github.com/railwayapp-templates/nextjs-prisma
- **Public domain:** Yes

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:latest

## Documentation

# Deploy and Host Next.js with Prisma on Railway

![Next.js logo](https://assets.vercel.com/image/upload/v1662130559/nextjs/Icon_dark_background.png)

Next.js is the React framework with **143,000+ GitHub stars**, and Prisma is the TypeScript ORM with **47,000+** — together they're a common full-stack starting point. This template deploys a Next.js app with Prisma and a PostgreSQL database on Railway, running migrations on every build. Vercel Pro is $20 per seat and still needs a separate database — on Railway, app and Postgres run side by side for a few dollars a month.

---

## What This Template Deploys

| Service | Purpose |
|---|---|
| **nextjs** | Next.js app with Prisma, built from GitHub. The build runs `prisma migrate deploy` before `next build`; served with `next start` on a public HTTPS domain. |
| **Postgres** | PostgreSQL with SSL, connected through `DATABASE_URL`. |
| **Persistent Volume** | Mounted on Postgres at `/var/lib/postgresql/data` — your data survives redeploys. |

Two services in one project: the app runs as a long-lived Node server, so API routes, server components and database connections behave the same as in development.

---

## About Hosting Next.js with a Database

Serverless Next.js hosting is quick for static pages, but a database-backed app adds connection limits, cold starts and a separate database provider to manage. Running `next start` on a server keeps a warm Prisma connection pool and puts the database next to the app.

On Railway, the build applies Prisma migrations automatically, then compiles Next.js; Postgres runs in the same project, and every push to your fork redeploys both code and schema changes.

**Update it before production.** The starter pins Next.js 13.1 and Prisma 4.9 from 2023 — upgrade both, since newer releases include security fixes. Also point `DATABASE_URL` at `${{Postgres.DATABASE_PRIVATE_URL}}` so database traffic stays on Railway's private network.

Typical cost: **~$3–8/month** on Railway for the app and database. Vercel Pro is $20 per developer seat (Hobby is non-commercial only), plus a database from another provider.

---

## Deploy Next.js + Prisma in Under 5 Minutes

1. Click **Deploy on Railway** — Railway forks the code, starts Postgres, runs migrations and builds Next.js (~3 minutes).
2. Open the public URL to see the app.
3. Change `DATABASE_URL` to the private Postgres URL and redeploy.
4. Edit `prisma/schema.prisma`, run `prisma migrate dev` locally and commit the migration.
5. Push — Railway applies the migration and redeploys.

No separate database vendor. No cold starts. No connection-pool workarounds.

---

## Common Use Cases

- **Vercel alternative with a database** — "deploy nextjs with postgres" in one project
- **Full-stack SaaS** — Next.js UI and API routes backed by Prisma models
- **Dashboards and internal tools** — server components reading straight from Postgres
- **E-commerce and content apps** — typed queries with Prisma
- **Learning full-stack TypeScript** — a working Next.js + ORM + database example
- **Prototypes** — a live full-stack app with migrations from day one

---

## Configuration

| Variable | Required | Description |
|---|---|---|
| `DATABASE_URL` | ✅ Auto-injected | Postgres connection for Prisma. Switch to `${{Postgres.DATABASE_PRIVATE_URL}}`. |
| `PORT` | Auto-set | Railway sets it; `next start --port ${PORT-3000}` uses it. |
| `NODE_ENV` | Optional | `production` is set automatically by `next start`. |

**Migrations run during the build.** If a migration fails, the build fails and the old version keeps running — check the build logs, fix the migration and push again.

---

## Next.js + Prisma on Railway vs. Alternatives

| | Next.js on Railway | Vercel | Render | Heroku |
|---|---|---|---|---|
| **Monthly cost (app + database)** | ~$3–8 usage | $20 per seat Pro + external database | Free tier sleeps; paid plus database | $7 Basic + $5 Postgres |
| **Postgres in the same project** | ✅ Yes | ⚠️ Via marketplace | ✅ Yes | ✅ Add-on |
| **Long-lived server (no cold starts)** | ✅ Yes | ❌ Serverless functions | ✅ On paid plans | ✅ On Basic |
| **Migrations on deploy** | ✅ In build | ⚠️ Your own setup | ⚠️ Your own setup | ⚠️ Release phase |
| **Commercial use on entry plan** | ✅ Yes | ❌ Hobby is non-commercial | ✅ Yes | ✅ Yes |
| **License** | ✅ MIT Next.js, Apache-2.0 Prisma | ❌ Proprietary platform | ❌ Proprietary platform | ❌ Proprietary platform |

---

## Dependencies for Next.js + Prisma Hosting

- Railway account — Hobby ($5/month) covers a small app and database.
- A GitHub account — Railway forks the starter so you own the code.

### Deployment Dependencies

- [Next.js Docs](https://nextjs.org/docs) — framework reference
- [Prisma Docs](https://www.prisma.io/docs) — schema and migrations
- [Railpack](https://railpack.com/) — Railway's zero-config builder
- [Railway Volumes Documentation](https://docs.railway.com/volumes) — persistence

### Implementation Details

The `build` script runs `yarn migrate:deploy && next build`, so `prisma migrate deploy` applies pending migrations against Postgres before compiling. The `start` script runs `next start --port ${PORT-3000}`, keeping one Node process with a warm Prisma connection pool.

Before production, upgrade Next.js and Prisma from their 2023 versions and move `DATABASE_URL` to the private Postgres URL.

---

## Frequently Asked Questions

**What does this Next.js template include?**
A Next.js app using Prisma ORM with a PostgreSQL database, where migrations run automatically during each build.

**How much does it cost compared to Vercel?**
About $3–8/month on Railway for app and database together. Vercel Pro is $20 per developer seat and you still need a database elsewhere; Vercel Hobby is for non-commercial use.

**Why does my build fail with a Prisma error?**
The build runs `prisma migrate deploy`; it fails if `DATABASE_URL` is wrong or a migration is broken. Check the build logs, fix the migration, and push again.

**Do I lose data when I redeploy?**
No. Data lives in Postgres on a persistent volume, and migrations only apply schema changes.

**Can I upgrade to the latest Next.js and Prisma?**
Yes, and you should: update `next`, `react`, `prisma` and `@prisma/client` in `package.json`, regenerate the client, and push.

**Does it support API routes and server-side rendering?**
Yes. It runs as a full Node server with `next start`, so API routes, SSR and server components all work.

---

## Why Deploy and Host Next.js with Prisma on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Next.js with Prisma on Railway, you get the app and its PostgreSQL database in one project, with migrations on every push, for a few dollars a month.


## Similar templates

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway
- [Appsmith](https://railway.com/deploy/appsmith-1) — Low-code platform for internal tools, dashboards, and admin panels.

Open this page in a browser: https://railway.com/deploy/nextjs-prisma-postgres
