DevOps28 February 20267 min read

Deploying a Next.js + PostgreSQL App on Render.com

From zero to production: web service configuration, database provisioning, environment variables, and keeping the free tier alive with a health-check cron job.

RenderPostgreSQLNext.jsDeployment

Render.com offers a surprisingly smooth experience for deploying full-stack Next.js apps with a managed PostgreSQL database. Here's my end-to-end setup.

Web Service Configuration

Set the build command to run migrations before building — this ensures the schema is always up to date before any code runs:

prisma generate && prisma migrate deploy && next build

Start command: npm start. Simple, predictable.

Environment Variables

Render injects DATABASE_URL automatically when you link a PostgreSQL service to your web service. Use the internal connection string (not the external one) — it routes within Render's private network and is both faster and more secure.

Keeping the Free Tier Warm

Render's free web services spin down after 15 minutes of inactivity. A simple cron job on cron-job.org hitting /api/health every 10 minutes keeps it warm with negligible traffic.

// app/api/health/route.ts
export function GET() {
  return Response.json({ ok: true });
}

Cloudflare DNS + Custom Domain

Point your domain's A record (or CNAME) to Render's provided hostname. Enable Cloudflare's proxy (orange cloud) for DDoS protection and edge caching — just make sure to disable "Always Use HTTPS" at the Cloudflare level since Render handles SSL termination.