Deploying to Vercel
Deploy Next.js web and API applications to Vercel with automatic optimizations, environment configuration, and seamless monorepo integration
Overview
This guide covers deploying the build-elevate monorepo to Vercel, the platform purpose-built for Next.js.
The monorepo contains multiple applications that can be deployed independently:
- Web (
apps/web) - Next.js 16 frontend application - API (
apps/api) - Express.js REST API backend
Prerequisites
- A Vercel account
- GitHub, GitLab, or Bitbucket account with monorepo access
- All environment variables configured
Deploying the Web Application
Step 1: Link Repository
- Go to vercel.com and click Add New Project
- Select your Git provider and authorize Vercel
- Find and select your monorepo
- Click Import
Step 2: Configure Web App
-
Set Root Directory
- Root Directory:
apps/web - Vercel auto-detects Next.js configuration
- Root Directory:
-
Environment Variables
- Navigate to Settings → Environment Variables
- Add the variables required by the web application:
NEXT_PUBLIC_API_URL- Backend API URL (e.g.,https://api.example.com)NEXT_PUBLIC_APP_URL- Frontend URL (auto-set by Vercel)
-
Build Settings
- Build Command:
pnpm build - Output Directory:
.next(auto-detected)
- Build Command:
Step 3: Deploy
Click Deploy to build and deploy your Next.js application.
Deploying the API
Step 1: Create API Project
- Click Add New Project in your Vercel dashboard
- Select the same repository
- Set Root Directory to
apps/api
Step 2: Configure API
-
Framework Detection
- Vercel may not auto-detect Express.js
- Ensure
package.jsonatapps/api/package.jsonhas correct exports
-
Environment Variables
- Add all required environment variables:
DATABASE_URL- PostgreSQL connection stringBETTER_AUTH_SECRET- Authentication secretGOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETRESEND_TOKEN- Email service API keyUPSTASH_REDIS_REST_URLand token - Rate limiting
- Add all required environment variables:
-
Build Settings
- Build Command:
pnpm build - Output Directory: Leave empty or set to
dist - Serverless Function: Node.js runtime
- Build Command:
Step 3: Deploy
Click Deploy to deploy your Express.js API as Vercel Functions.
Environment Variables Reference
All applications share these core variables:
| Variable | Type | Purpose |
|---|---|---|
DATABASE_URL | Secret | PostgreSQL connection string |
BETTER_AUTH_SECRET | Secret | Auth encryption key (32+ chars) |
GOOGLE_CLIENT_ID | Secret | OAuth client ID |
GOOGLE_CLIENT_SECRET | Secret | OAuth client secret |
RESEND_TOKEN | Secret | Email service API token |
UPSTASH_REDIS_REST_URL | Secret | Redis REST API endpoint |
UPSTASH_REDIS_REST_TOKEN | Secret | Redis API token |
NEXT_PUBLIC_API_URL | Public | Backend API URL (web app only) |
NEXT_PUBLIC_APP_URL | Public | Frontend URL (auto-set by Vercel) |
For detailed setup instructions and descriptions of all environment variables, see the Configuration Guide.
Post-Deployment
Verify Applications
-
Test Web Application
- Visit the provided Vercel URL
- Verify authentication flows
- Test API connectivity
-
Test API Endpoints
- Use curl or Postman to test endpoints
- Verify database connectivity
- Check rate limiting works
Database Migrations
Run database migrations after deploying API:
pnpm db:migrateOr use a custom build step in Vercel:
cd apps/api && npm run db:migrate && npm run buildCustom Domains
- Go to your project Settings → Domains
- Add your custom domain
- Follow DNS configuration steps
Monitoring
Monitor your deployments:
- Analytics - View traffic and performance
- Logs - Check build and runtime logs
- Deployments - Toggle between versions
- Preview URLs - Test pull requests automatically
Troubleshooting
Build Fails with Module Not Found
Ensure pnpm configuration is correct:
pnpm-workspace.yamlexists at root- All workspace dependencies are installed:
pnpm install
Environment Variables Not Loading
- Verify variables are set in Vercel dashboard
- Check variable names exactly match your code
- Redeploy after updating variables
- For public variables, prefix with
NEXT_PUBLIC_
API Not Connecting
- Verify
API_URLmatches deployed API domain - Check CORS configuration in Express app
- Ensure
ALLOWED_ORIGINSincludes web domain
Next Steps
- Set up GitHub integration for preview deployments
- Configure custom domains and SSL
- Enable Analytics for performance monitoring
- Set up error tracking
Deployment
Production deployment strategies, best practices, security considerations, and environment setup guides for deploying applications to Vercel and other platforms
Troubleshooting
Solutions for common issues including port conflicts, dependency problems, database errors, and environment configuration errors