Courses Curriculum Cities Blog Enroll Now
Next.js Full-Stack · Day 5 of 5 ~35 minutes

Day 5: Deploy to Vercel with Environment Variables

Deploy your full-stack Next.js app to Vercel, configure production environment variables, set up a production database, and establish a CI/CD pipeline from GitHub.

1
Day 1
2
Day 2
3
Day 3
4
Day 4
5
Day 5
What You'll Build

A live Next.js app deployed to Vercel with a production PostgreSQL database, environment variables configured, automatic deploys on push, and preview deployments for every PR.

1
Section 1 · 8 min

Prepare for Production

Before deploying, make sure your app is ready. Run the build locally to catch type errors, check that all env vars have examples, and make sure the database URL points to production.

bashterminal
# Run the production build locally
npm run build
# This catches TypeScript errors and missing imports

# Check that you have .env.example
cat .env.example
text.env.example
# Database
DATABASE_URL="postgresql://..."

# NextAuth
NEXTAUTH_URL="https://your-domain.com"
NEXTAUTH_SECRET="generate-with-openssl-rand-base64-32"

# GitHub OAuth
GITHUB_ID="your-github-client-id"
GITHUB_SECRET="your-github-client-secret"
2
Section 2 · 10 min

Set Up a Production Database

SQLite doesn't work on Vercel (no persistent filesystem). Use Vercel Postgres (powered by Neon) for a free serverless PostgreSQL database.

bashvercel CLI
# Install Vercel CLI
npm install -g vercel
vercel login

# Create a Vercel Postgres database
vercel postgres create my-db
# This creates a PostgreSQL database and gives you the connection string

# Pull env vars from Vercel to your local .env
vercel env pull .env.local
textprisma/schema.prisma (update datasource)
datasource db {
  provider          = "postgresql"
  url               = env("POSTGRES_URL")
  directUrl         = env("POSTGRES_URL_NON_POOLING")
}
bashterminal
# Push schema to production database
npx prisma db push
3
Section 3 · 9 min

Deploy to Vercel

Vercel detects Next.js automatically and configures the build settings. Connect your GitHub repo once and every push triggers a new deployment.

bashterminal
# Deploy from CLI
vercel --prod
# Your project is now at https://your-project.vercel.app

# Or connect via GitHub at vercel.com:
# 1. Import repository
# 2. Add environment variables
# 3. Deploy

# Set NEXTAUTH_SECRET
openssl rand -base64 32
# Copy output → Vercel Environment Variables → NEXTAUTH_SECRET

Preview deployments: Every pull request gets its own unique preview URL (like your-project-git-feature-username.vercel.app). Share it with teammates for review before merging.

4
Section 4 · 8 min

Custom Domain and Performance

Add a custom domain and review Vercel's built-in analytics to understand your app's performance in production.

bashterminal
# Add custom domain via Vercel CLI
vercel domains add yourdomain.com

# Check deployment logs
vercel logs

# Inspect specific deployment
vercel inspect [deployment-url]

In your Vercel dashboard, enable Web Analytics (free) to see page views, Core Web Vitals scores, and geography. For production apps, check that all pages have a First Contentful Paint under 1.8 seconds.

Run Prisma migrations in production: Add "postinstall": "prisma generate" to your package.json scripts. For migrations (not just pushes), run npx prisma migrate deploy as part of your build step in Vercel's Build Command.

What You Learned Today

  • Built the production Next.js bundle locally and caught errors before deploying
  • Set up Vercel Postgres as the production database and migrated the Prisma schema
  • Deployed the full-stack app to Vercel with all environment variables configured
  • Enabled preview deployments so every PR gets a live test URL automatically
Your Challenge

Go Further on Your Own

  • Set up a custom domain and configure the NEXTAUTH_URL environment variable
  • Add Vercel Speed Insights to monitor Core Web Vitals in production
  • Set up Sentry (sentry.io) for error tracking in production — 5 minute setup with the Vercel integration
Day 5 Complete

Course Complete!

You finished all 5 days. Ready to go deeper?

Reserve Your Bootcamp Seat
Course Progress
100%

Want live instruction and hands-on projects? Join the AI bootcamp — 3 days, 5 cities.

Finished this lesson?