Environment Variables

Managing secrets and configuration for different deployment environments.

Environment variables store configuration values and secrets that your application needs, like API keys and database URLs. They're kept separate from code so different environments (development, preview, production) can use different values.

Never Commit Secrets

Never commit secrets to your repository. Use environment variables instead. Even for "private" repositories, secrets in code are a security risk.

Vercel supports different environment variables for different contexts:

EnvironmentWhen UsedExample Use Case
Developmentvercel dev locallyLocal development settings
PreviewPreview deployments (branches)Staging/test API keys
ProductionProduction deployments (main)Live API keys

In Next.js projects, access environment variables using:

// Server-side (API routes, getServerSideProps, etc.)
const apiKey = process.env.API_KEY;
const dbUrl = process.env.DATABASE_URL;

// Client-side (NEXT_PUBLIC_ prefix required)
const publicKey = process.env.NEXT_PUBLIC_FIREBASE_API_KEY;

// Example usage
const firebaseConfig = {
  apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
  authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
  storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
};
NEXT_PUBLIC_ Prefix

Variables with the NEXT_PUBLIC_ prefix are exposed to the browser. Only use this for values that are safe to be public (like Firebase client config). Keep sensitive values (like API secrets) server-side only.

For Olive Code projects, environment variables are typically pre-configured. If you need to view or modify them:

  1. Via Vercel Dashboard

    Go to vercel.com → Select Project → Settings → Environment Variables

  2. Via Vercel CLI

    Use vercel env ls to list variables and vercel env add to add new ones.

  3. Local Development

    Create a .env.local file (gitignored) with your local development values.

# .env.local (for local development)
NEXT_PUBLIC_FIREBASE_API_KEY=your-api-key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
# ... other variables

Here are environment variables commonly used in Olive Code projects:

VariablePurposeClient/Server
NEXT_PUBLIC_FIREBASE_API_KEYFirebase client initializationClient
NEXT_PUBLIC_FIREBASE_AUTH_DOMAINFirebase auth domainClient
NEXT_PUBLIC_FIREBASE_PROJECT_IDFirebase project identifierClient
FIREBASE_SERVICE_ACCOUNTFirebase admin SDK credentialsServer only
DATABASE_URLDatabase connection stringServer only
Vercel Environment Variables Documentation

Complete Vercel Environment Variables Guide