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 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:
| Environment | When Used | Example Use Case |
|---|---|---|
| Development | vercel dev locally | Local development settings |
| Preview | Preview deployments (branches) | Staging/test API keys |
| Production | Production 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,
};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:
- Via Vercel Dashboard
Go to vercel.com → Select Project → Settings → Environment Variables
- Via Vercel CLI
Use
vercel env lsto list variables andvercel env addto add new ones. - Local Development
Create a
.env.localfile (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:
| Variable | Purpose | Client/Server |
|---|---|---|
NEXT_PUBLIC_FIREBASE_API_KEY | Firebase client initialization | Client |
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN | Firebase auth domain | Client |
NEXT_PUBLIC_FIREBASE_PROJECT_ID | Firebase project identifier | Client |
FIREBASE_SERVICE_ACCOUNT | Firebase admin SDK credentials | Server only |
DATABASE_URL | Database connection string | Server only |