Deploy Next.js + Prisma + PostgreSQL Starter
Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.
Just deployed
Just deployed
/var/lib/postgresql/data
Deploy and Host Next.js with Prisma on Railway
![]()
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
- Click Deploy on Railway — Railway forks the code, starts Postgres, runs migrations and builds Next.js (~3 minutes).
- Open the public URL to see the app.
- Change
DATABASE_URLto the private Postgres URL and redeploy. - Edit
prisma/schema.prisma, runprisma migrate devlocally and commit the migration. - 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 — framework reference
- Prisma Docs — schema and migrations
- Railpack — Railway's zero-config builder
- Railway Volumes Documentation — 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.
Template Content
