Next.js + PostgreSQL
The Next.js + PostgreSQL template deploys a full-stack web application with a database, ready for production use.
What’s included
| Service | Image/Source | Port |
|---|---|---|
| Web | Your Next.js repository | 3000 |
| PostgreSQL | postgres:16 | 5432 |
How it works
When you deploy this template:
- PostgreSQL is created with auto-generated credentials and persistent storage
- Your Next.js app is cloned from GitHub, built, and deployed
DATABASE_URLis automatically injected into your web service- Both services are connected via private networking
Your Next.js app can immediately query the database without any manual configuration:
import { Pool } from 'pg';
const pool = new Pool({ connectionString: process.env.DATABASE_URL,});
const result = await pool.query('SELECT NOW()');Deploying
- Go to Templates → Next.js + PostgreSQL
- Enter your GitHub repository URL
- Select the branch to deploy
- Click Deploy
Your app will be live within a few minutes at your-project.your-org.stackpad.eu.
Customizing
After deployment, you can:
- Add environment variables for your app
- Configure a custom domain
- Add Redis for caching
- Set up preview deployments for pull requests
Recommended Next.js config
For the best deployment performance, add standalone output to your next.config.js:
/** @type {import('next').NextConfig} */const nextConfig = { output: 'standalone',};
export default nextConfig;This creates a minimal production bundle that starts faster and uses less memory.
What’s next?
- PostgreSQL guide — learn more about managing PostgreSQL on Stackpad
- Custom domains — add your own domain
- Environment variables — configure your app