How to Deploy a Full-Stack Next.js App with PostgreSQL in Under 60 Seconds on Deployxa
If you have ever tried to deploy a full-stack Next.js application with a PostgreSQL database, you already know the pain. You set up your project locally, everything works beautifully with Prisma or Drizzle, and then you hit the deployment wall. Vercel tells you that serverless functions have execution time limits and you need a separate database host. Railway gives you a blank canvas and expects you to wire up build commands, environment variables, and database connections manually. AWS and DigitalOcean? You are looking at hours of configuration before writing a single line of production code.
The problem is not your code. The problem is that most deployment platforms treat Next.js as a frontend framework first and a backend framework second. They optimize for static sites and API routes running in serverless environments, leaving you to figure out database connections, connection pooling, persistent storage, and background processes on your own. You end up gluing together multiple services: one for hosting, one for the database, one for file storage, one for caching. Each integration point is a potential failure point and a mental overhead you do not need.
Deployxa takes a fundamentally different approach. Instead of asking you to write a Dockerfile, configure build commands, or manually provision a database, Deployxa's AI build engine analyzes your codebase the moment you push it and configures everything automatically. It detects Next.js, identifies that you are using PostgreSQL through Prisma or Drizzle, provisions a managed database instance, sets your connection strings, and has your application live in under 60 seconds. No configuration files. No manual intervention. No multi-service assembly required.
This article walks you through the entire process, from a blank Next.js project to a fully deployed, production-ready application with authentication, a PostgreSQL database, server actions, and a custom domain. Every step is documented with real code examples so you can follow along and deploy your own full-stack Next.js app today.
What You Will Build
To make this tutorial concrete and immediately useful, you are going to build a real full-stack Next.js application, not a simplified hello-world example that falls apart the moment you add a database. The application will include the following components that represent what most production Next.js apps actually need.
First, you will set up a Next.js project using the App Router, which is the modern standard for Next.js applications. The app will have a public-facing homepage, a protected dashboard route that requires authentication, and a simple task management interface where users can create, read, update, and delete tasks stored in PostgreSQL.
On the database side, you will use Prisma as your ORM with a PostgreSQL database. The schema will include User and Task models with a one-to-many relationship. You will write server actions that handle form submissions and database mutations directly from your React components, taking full advantage of the server-first data fetching pattern that makes Next.js so powerful.
For authentication, you will implement a session-based auth flow using NextAuth.js configured to work with your PostgreSQL database. This gives you protected routes, a sign-in page, and a sign-out mechanism out of the box without writing custom authentication logic.
The finished application will have multiple routes, server-side rendering, server actions for mutations, database queries through Prisma, and authentication middleware. This is not a toy project. It is the foundation of a real SaaS application. And Deployxa will deploy the entire thing, database included, in a single push.
Prerequisites
Before you begin, make sure you have the following tools and accounts ready. Nothing here is unusual or difficult to obtain, but having everything prepared beforehand will make the deployment process completely smooth.
You need a GitHub account. Deployxa connects directly to your GitHub repositories, so your code needs to be hosted there. If you do not already have a GitHub account, create one at github.com. It is free. You also need Git installed on your local machine so you can push code to your repository.
You need a Deployxa account. Sign up at deployxa.com. The free tier is more than sufficient for this tutorial and includes everything you need: one application deployment, a managed PostgreSQL database, custom domain support, and preview deployments. No credit card is required to get started.
You should have a working understanding of Next.js fundamentals. You do not need to be an expert, but you should be comfortable with the App Router, React components, and basic server-side rendering concepts. If you have built even one Next.js project before, you are ready.
Finally, make sure you have Node.js version 18 or later installed on your machine. You can check your version by running node -v in your terminal. If you need to install or update Node.js, download it from nodejs.org or use a version manager like nvm.
Step 1: Set Up Your Next.js Project
Start by creating a new Next.js project with TypeScript and the App Router. Open your terminal and run the following command:
npx create-next-app@latest my-fullstack-app --typescript --tailwind --eslint --app --src-dir --import-alias "@/*"
cd my-fullstack-appThis gives you a clean Next.js project with TypeScript, Tailwind CSS, and the App Router structure. Next, install the dependencies you need for the full-stack functionality:
npm install prisma @prisma/client next-auth@beta @auth/prisma-adapter
npm install -D prisma
npx prisma initNow define your database schema. Open the prisma/schema.prisma file and replace its contents with the following:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
name String?
email String @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
tasks Task[]
}
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String?
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
model Task {
id String @id @default(cuid())
title String
description String?
completed Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}Create a Prisma client singleton in src/lib/prisma.ts to prevent multiple instances during development:
import { PrismaClient } from "@prisma/client";
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
export const prisma = globalForPrisma.prisma || new PrismaClient();
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;Now create a server action for adding tasks in src/app/actions.ts:
"use server";
import { prisma } from "@/lib/prisma";
import { revalidatePath } from "next/cache";
export async function createTask(formData: FormData) {
const title = formData.get("title") as string;
const description = formData.get("description") as string;
if (!title) {
return { error: "Title is required" };
}
await prisma.task.create({
data: {
title,
description: description || null,
userId: "user-id-here", // Replace with actual auth user ID
},
});
revalidatePath("/dashboard");
}
export async function getTasks() {
return prisma.task.findMany({
orderBy: { createdAt: "desc" },
});
}
export async function deleteTask(id: string) {
await prisma.task.delete({ where: { id } });
revalidatePath("/dashboard");
}Your full-stack project is now ready. You have a database schema, a Prisma client, and server actions that handle CRUD operations. The next step is getting this code into GitHub.
Step 2: Push to GitHub
With your project ready, the next step is to push it to a GitHub repository. This is the only step where you do any manual work outside of Deployxa, and it takes about two minutes.
First, initialize a Git repository inside your project directory if you have not already. Then create a .gitignore file to exclude node_modules, the .next build directory, and environment files. The create-next-app command already generates a .gitignore for you, but double-check that it includes the following entries:
node_modules/
.next/
.env
.env.local
.env*.localCreate a new repository on GitHub. You can do this through the GitHub web interface by clicking the "New repository" button on your profile page. Name it something descriptive like my-fullstack-app. Do not initialize it with a README, because you already have a local repository.
Back in your terminal, add the remote origin and push your code:
git add .
git commit -m "Initial commit: full-stack Next.js with Prisma and PostgreSQL"
git remote add origin https://github.com/your-username/my-fullstack-app.git
git branch -M main
git push -u origin mainThat is it. Your code is now on GitHub and ready for Deployxa to pick it up. There is no need to add any deployment configuration files, no Dockerfile, no docker-compose.yml, and no CI/CD pipeline definitions. Deployxa handles all of that based on what it finds in your codebase.
Step 3: Connect to Deployxa
This is where the magic happens. Log in to your Deployxa dashboard at deployxa.com and click the "New Project" button. You will be prompted to connect a GitHub repository. Select the my-fullstack-app repository you just pushed.
The moment you select the repository, Deployxa's AI-powered build detection system goes to work. It clones your repository, scans the file structure, reads your package.json, inspects your Prisma schema, and identifies the following:
- Framework: Next.js (detected from the next dependency in package.json and the app/ directory structure)
- Language: TypeScript (detected from tsconfig.json)
- Database: PostgreSQL (detected from the provider = "postgresql" line in your Prisma schema)
- ORM: Prisma (detected from the @prisma/client dependency and schema.prisma file)
- Build command: Automatically set to npx prisma generate && next build
- Start command: Automatically set to next start
- Port: Automatically detected as 3000 from Next.js defaults
All of this happens in seconds. You do not need to write a single configuration line. There is no build settings panel to fill out, no dropdown to select your framework, and no field where you type in a Dockerfile path. The AI engine reads your code and knows exactly what to do.
Compare this to other platforms where you would need to manually select "Next.js" from a dropdown, type in your build command, configure your database separately, and wire up the connection string yourself. Deployxa eliminates all of that friction.
Step 4: Configure Your Database
Since Deployxa detected PostgreSQL in your Prisma schema, it automatically offers to provision a managed PostgreSQL database for your project. Click "Provision Database" and Deployxa creates a fully managed PostgreSQL instance in your preferred region.
The database provisioning takes about 15 seconds. Once it is ready, Deployxa automatically generates a connection string in the following format and makes it available as a project secret:
postgresql://deployxa_user:[email protected]:5432/my_fullstack_app?sslmode=requireYou do not need to copy this string manually. Deployxa injects it as the DATABASE_URL environment variable, which is exactly what your Prisma schema expects. The connection between your application and your database is established automatically.
After the database is provisioned, you need to run your Prisma migrations. Deployxa provides a "Run Migrations" button in the project dashboard. Clicking it executes npx prisma db push (or npx prisma migrate deploy if you have migration files) against your production database, creating all the tables defined in your schema. This is a zero-downtime deployment operation, so your users will never see an interruption.
If you prefer to run migrations manually, you can open a remote terminal session directly from the Deployxa dashboard and execute any Prisma command you need. This is useful for complex migration scenarios where you want to review the SQL before applying it.
Step 5: Set Environment Variables
Every real application needs environment variables for configuration: authentication secrets, API keys, OAuth provider credentials, and similar values that must not be hardcoded in your source code. Deployxa provides a first-class environment variable management system that makes this painless.
In your Deployxa project dashboard, navigate to the "Environment Variables" section. You will see that DATABASE_URL is already populated from the database provisioning step. Add the following additional variables for NextAuth and general application configuration:
NEXTAUTH_SECRET=your-randomly-generated-secret
NEXTAUTH_URL=https://your-app.deployxa.appTo generate a secure value for NEXTAUTH_SECRET, you can run openssl rand -base64 32 in your local terminal and paste the result into the Deployxa dashboard.
If you are using OAuth providers like Google or GitHub for authentication, add those credentials as well:
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secretDeployxa encrypts all environment variables at rest and injects them into your application's runtime environment during the build and deployment process. Variables are scoped to individual environments, so you can have different values for production, staging, and preview deployments without any risk of cross-contamination.
Step 6: Deploy and Go Live
You have pushed your code, connected your repository, provisioned your database, and configured your environment variables. Now click the "Deploy" button and watch what happens.
During the first 10 seconds, Deployxa pulls your latest commit, installs all dependencies from your package-lock.json, and sets up the build environment. The AI engine has already determined that this is a Next.js project with Prisma, so it knows to run prisma generate before next build to ensure your Prisma client is available during the build step.
Between seconds 10 and 40, Next.js compiles your application. Server components are pre-rendered, static pages are generated, and client components are bundled. Because Deployxa uses optimized build infrastructure with caching, subsequent deployments are even faster. If you have not changed any dependencies, the install step is skipped entirely and only the changed files are rebuilt.
Between seconds 40 and 55, Deployxa packages your application into a lightweight container image. This is not a generic Node.js image with your code copied in. Deployxa creates a purpose-built container optimized for your specific Next.js version and configuration. The container includes only the runtime dependencies needed for production, keeping the image size minimal.
In the final 5 seconds, Deployxa routes traffic to your new container, verifies the health check endpoint, and your application is live. Open the URL displayed in your dashboard, and you will see your full-stack Next.js application running in production with a real PostgreSQL database backing it.
Total time: under 60 seconds. No Dockerfile. No manual configuration. No multi-step deployment guide to follow.
What Deployxa Does Automatically
It is worth pausing to appreciate everything that happens behind the scenes when you click that deploy button, because understanding the automation helps you trust the platform and debug issues faster when they arise.
Framework detection: Deployxa reads your package.json, identifies the framework and its version, and configures the build pipeline accordingly. It supports Next.js, Nuxt, Remix, SvelteKit, Astro, and many other frameworks. Each framework gets a tailored build configuration optimized for its specific requirements.
Dependency installation: Deployxa caches your node_modules between deployments. If your dependencies have not changed, the installation step takes less than a second. When dependencies do change, only the diff is downloaded and installed, not the entire dependency tree.
Build configuration: The AI engine determines the correct build command, output directory, and start command for your project. For Next.js, it knows to use next build and next start. For Prisma projects, it injects the prisma generate step. For projects with Tailwind CSS, it ensures PostCSS is configured correctly.
Container packaging: Deployxa creates an optimized OCI container image for your application. The image is based on a minimal runtime, includes only production dependencies, and is configured with the correct user permissions, health checks, and port bindings.
SSL and CDN: Every Deployxa application gets automatic SSL through Let's Encrypt certificates that are provisioned and renewed without any action on your part. Your application is also served through Deployxa's global CDN, ensuring fast response times for users around the world.
Custom Domains and SSL Setup
A custom domain is essential for any production application. Deployxa makes this straightforward. In your project dashboard, navigate to the "Domains" section and click "Add Domain." Enter your domain name, for example app.yourstartup.com.
Deployxa will provide you with a CNAME record to add to your DNS configuration. The record will point to something like cname.deployxa.app. Log in to your domain registrar, whether that is Cloudflare, Namecheap, GoDaddy, or any other provider, and add the CNAME record to your DNS zone.
DNS propagation typically takes between 5 minutes and 48 hours depending on your registrar. Once the DNS record is active, Deployxa automatically provisions an SSL certificate for your custom domain using Let's Encrypt. This happens without any input from you. There is no certificate to download, no CSR to generate, and no manual renewal process.
Deployxa also supports apex domains (root domains like yourstartup.com) through an A record configuration. The dashboard provides clear instructions for both CNAME and A record setups, so you never have to guess which one to use.
Preview Deployments for PRs
One of the most valuable features for teams and solo developers alike is Deployxa's automatic preview deployments. Every time you push code to a pull request branch, Deployxa creates a completely separate deployment with its own URL, its own environment, and optionally its own database.
This means you can open a pull request with a new feature, and Deployxa will generate a unique preview URL like pr-42-my-feature.my-fullstack-app.deployxa.app. You can share this URL with your team, with stakeholders, or with clients for review before merging into production.
Preview deployments use the same build pipeline as production, so they accurately reflect how your changes will behave in the live environment. Environment variables are inherited from your production configuration but can be overridden for specific preview deployments if needed.
When the pull request is merged, the preview deployment is automatically cleaned up. When it is closed without merging, the preview is removed as well. This keeps your deployment list clean and ensures you are not paying for resources you no longer need.
Scaling and Performance
Deployxa scales your application automatically from zero. When there is no traffic, your application scales down to zero instances, and you stop paying for compute resources. When a request comes in, Deployxa scales up within milliseconds to handle the load. This is ideal for indie hackers and solo founders who want to keep costs low during early stages while maintaining the ability to handle traffic spikes.
The scaling is not just about spinning up more instances. Deployxa also manages connection pooling for your PostgreSQL database. Database connections are a finite resource, and without pooling, each application instance would open its own connection, exhausting the database's capacity under load. Deployxa handles this transparently, ensuring your database remains responsive even as your application scales.
For applications that need more control, Deployxa provides scaling configuration options. You can set minimum and maximum instance counts, configure memory and CPU limits, and define scaling triggers based on request rate or response time. But for most Next.js applications, the default automatic scaling is more than sufficient.
Comparison: Deployxa vs Vercel vs Railway for Next.js + PostgreSQL
Let me be direct about how Deployxa compares to the two most common alternatives for deploying Next.js applications.
Vercel is the company behind Next.js, so it has the deepest framework integration. However, Vercel is designed primarily for frontend and serverless workloads. When you add a database, you are on your own. Vercel does not provide managed PostgreSQL. You need to sign up for a separate database service like Supabase, Neon, or PlanetScale, configure the connection string in Vercel, and manage the integration yourself. Serverless functions also have execution time limits that can cause issues with long-running server actions or Prisma migrations. If your app does anything beyond simple API routes and static pages, you will hit friction.
Railway offers a more integrated experience with both application hosting and managed databases. However, Railway requires manual configuration. You need to create a separate database service, link it to your application, configure the build command, and manage environment variables across services. The initial setup takes 15 to 30 minutes, and every new project requires repeating these steps. Railway also does not offer automatic preview deployments on pull requests without additional configuration.
Deployxa combines the framework expertise of Vercel with the database integration of Railway, but eliminates the manual configuration that both platforms require. The AI build engine detects your stack and configures everything automatically. Managed PostgreSQL is built in, not a separate service. Preview deployments work out of the box. Custom domains and SSL are one-click setup. And the entire deployment process takes under 60 seconds instead of 15 to 30 minutes.
Conclusion
Deploying a full-stack Next.js application with PostgreSQL does not have to be a multi-hour ordeal involving Dockerfiles, build command configuration, separate database provisioning, and manual environment variable management. Deployxa's AI-powered platform analyzes your code, provisions your infrastructure, and delivers your application to production in under 60 seconds.
The workflow is simple. Write your Next.js application with Prisma, push it to GitHub, connect the repository in Deployxa, and click deploy. The AI engine handles framework detection, dependency installation, build configuration, container packaging, database provisioning, SSL certificate management, and CDN distribution automatically.
Whether you are a solo founder shipping your first SaaS product, an indie hacker iterating on side projects, or a developer who simply wants to spend less time on infrastructure and more time on features, Deployxa removes the deployment bottleneck entirely.
Sign up for a free Deployxa account at deployxa.com and deploy your first full-stack Next.js application today. No credit card required. No Dockerfile needed. Just push your code and watch it go live.