Deploy Next.js with Neon Postgres

Next.js app that uses Instagres to generate a claimable db at Neon.

Deploy Next.js with Neon Postgres

neon-railway-nextjs

neondatabase-labs/neon-railway-nextjs

Just deployed

Deploy and Host Next.js with Neon Postgres on Railway

Next.js with Neon Postgres combines React's powerful framework with serverless Postgres that features instant provisioning, database branching, and autoscaling. Using Neon's Instagres, you get a production-ready database in seconds without signup, making it perfect for rapid prototyping and full-stack applications.

About Hosting Next.js with Neon Postgres

Deploying Next.js with Neon Postgres on Railway leverages Neon's Instagres for immediate database provisioning. Your Next.js application connects to a fully-managed serverless Postgres database that automatically scales based on load and scales to zero during idle periods. The database is initially claimable for 72 hours, giving you time to develop and test before claiming it to a Neon account. This workflow combines Railway's seamless deployment with Neon's developer-first database features like branching, point-in-time recovery, and connection pooling.

Common Use Cases

  • Full-stack applications requiring serverless Postgres with autoscaling capabilities
  • Prototype and MVP development with instant database provisioning via Instagres
  • Applications needing database branching for isolated development, testing, and CI/CD workflows
  • Multi-tenant SaaS applications leveraging Neon's database-per-tenant architecture
  • Projects requiring scale-to-zero functionality to minimize costs during low-traffic periods

Dependencies for Next.js with Neon Postgres Hosting

  • Next.js (App Router or Pages Router)
  • Neon Postgres database (provisioned via Instagres)
  • PostgreSQL client library (e.g., @neondatabase/serverless, pg, drizzle, ...)
  • Environment variables for database connection strings (provided automatically by Instagres)

Deployment Dependencies

Implementation Details

Connecting to Neon with the serverless driver:

import { neon } from '@neondatabase/serverless'

const sql = neon(process.env.DATABASE_URL!)

export async function GET() {
  const posts = await sql`SELECT * FROM posts ORDER BY created_at DESC`
  return Response.json({ posts })
}

Using Instagres:

# Generate database and write credentials to .env
# `prefix` flag will adjust the prefix for public env_vars
npx get-db --yes --prefix NEXT_

# Seed the database with initial schema
npx get-db --seed ./schema.sql

Environment variables provided by Instagres:

DATABASE_URL=postgresql://...          # Direct connection
DATABASE_URL_POOLER=postgresql://...   # Pooled connection

Claiming your database:

After development, claim your database to keep it permanently by visiting the claim URL provided in your .env file or by running:

npx get-db claim

Why Deploy Next.js with Neon Postgres 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 Neon Postgres on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway. Neon's serverless Postgres adds powerful features like database branching, autoscaling, and scale-to-zero that keep your costs optimized while maintaining production-grade performance.


Template Content

More templates in this category

View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

View Template
Mellow Vue
A full-stack Vue app with The Boring JavaScript Stack.

View Template
NextJS 15.5 (Server Actions) with Shadcn
Better-Auth Ready with Auth flows and Server actions (Prod ready)