Environment Variables

Learn how to securely manage environment variables for different deployment environments on Vercel.

Setup Process

1

Access Project Settings

Navigate to your project in the Vercel dashboard and click on 'Settings'

2

Environment Variables

Select 'Environment Variables' from the left sidebar

3

Add Variables

Click 'Add New' and enter your key-value pairs

4

Configure Environments

Select which environments (Production/Preview/Development) should use each variable

Required Variables

Essential

Core Variables

Essential environment variables for the application:

# Database Connection
DATABASE_URL="postgres://username:password@host:port/database"

# Authentication
NEXTAUTH_URL="https://your-domain.com"
NEXTAUTH_SECRET="your-secret-key"

# Email Service
RESEND_API_KEY="re_123456789"

# AWS S3
AWS_ACCESS_KEY_ID="your-access-key"
AWS_SECRET_ACCESS_KEY="your-secret-key"
AWS_REGION="your-region"
S3_UPLOAD_BUCKET="your-bucket-name"

# Stripe
STRIPE_SECRET_KEY="sk_live_123456789"
STRIPE_WEBHOOK_SECRET="whsec_123456789"

# Redis
UPSTASH_REDIS_REST_URL="your-redis-url"
UPSTASH_REDIS_REST_TOKEN="your-redis-token"

Environment Configuration

Production

Live environment settings

  • Use production API keys
  • Live database credentials
  • Production URLs

Preview

PR and branch deployments

  • Test API credentials
  • Staging database
  • Test webhooks

Best Practices

Security

  • Never commit .env files
  • Use strong, unique values
  • Rotate secrets regularly
  • Limit access to production values

Organization

  • Use clear, descriptive names
  • Group related variables
  • Document all variables
  • Validate required variables

Local Development

For local development, create a .env.local file in your project root:

Local Environment

Example .env.local file:

# Use development/test credentials
DATABASE_URL="postgres://localhost:5432/myapp_dev"
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="development-secret-key"

# Test API keys
STRIPE_SECRET_KEY="sk_test_123456789"
RESEND_API_KEY="re_test_123456789"