Overview
Each application in the monorepo manages environment variables differently based on its deployment strategy:- SPA & Web: Local
.envfiles are the source of truth - Expo: EAS project environment is the source of truth
SPA Environment Variables
The SPA uses.env.dev and .env.prod files for development and production environments.
Local Setup
Create Environment Files
Create
.env.dev and .env.prod files in apps/spa/:apps/spa/.env.dev
apps/spa/.env.prod
Environment variables in Vite must be prefixed with
VITE_ to be exposed to the client-side code.GitHub Secrets Setup
Create GitHub Environments
Create two environments in your GitHub repository:
- Navigate to:
Settings→Environments→New environment - Create
devenvironment - Create
prodenvironment
The CI workflow (
.github/workflows/ci.yml) references these secrets as secrets.SPA_ENV_FILE and writes them to the appropriate file during the build process.Web Environment Variables
The Web app uses the same pattern as SPA but with Next.js environment variable conventions.Local Setup
- Variables prefixed with
NEXT_PUBLIC_are exposed to the browser - Server-side variables (like
DATABASE_URL) are only available in server components and API routes
GitHub Secrets Setup
Expo Environment Variables
Setup EAS Environment
Set Environment Variables in EAS Dashboard
Go to your EAS project dashboard and add environment variables:Required Variables:
APP_VARIANT: Set todevelopment,preview, orproductionEXPO_PUBLIC_APP_VARIANT: Set to your API URL (e.g.,https://dummyjson.com)
Variables prefixed with
EXPO_PUBLIC_ are exposed to the client-side code. Others are only available during build time.Local Environment File
The.env.local.example file in apps/expo/ shows available environment variables but is not used directly. It’s only for reference.
Vercel Deployment (SPA & Web)
When deploying to Vercel, environment variables must be configured in the Vercel dashboard.Add Variables
Add each environment variable from your
.env.prod file:- Set the environment scope (Production, Preview, Development)
- Use the same variable names and values
Best Practices
Source of Truth:
- SPA & Web: Local
.envfiles are the source of truth. When changing them, update deployment/CI project environments too. - Expo: EAS project environment is the source of truth. Pull changes to local files using
eas env:pull.
Security
Organization
- Group related variables together with comments
- Use descriptive variable names
- Document required variables in README files
- Keep
.env.examplefiles up to date
CI/CD Integration
The CI workflow automatically handles environment files:.github/workflows/ci.yml
Troubleshooting
Variables Not Loading
- SPA/Web: Ensure the dev script is copying the env file correctly
- Expo: Pull the latest environment variables from EAS
- Restart the development server after changing environment variables
Build Failures
- Check that all required variables are set in the deployment environment
- Verify variable names match exactly (case-sensitive)
- Ensure GitHub secrets are set in the correct environment (
devvsprod)
Quick Reference
| App | Source of Truth | Dev Command | Pull Remote Env |
|---|---|---|---|
| SPA | Local .env files | bun spa dev | Update GitHub secrets |
| Web | Local .env files | bun web dev | Update GitHub secrets |
| Expo | EAS project env | bun expo dev | bun expo env:pull:dev |
