Overview
Environment variables let you configure your app for different environments without changing code. Expo provides built-in support for environment variables with special security considerations for mobile apps.Types of Environment Variables
Public variables
Embedded in your app bundle, accessible at runtime:Build-time variables
Used during the build process, not included in the bundle:Using .env Files
Install dotenv
Create .env file
.env
Load variables
app.config.js
Access in your app
utils/config.ts
Multiple Environments
Environment-specific files
Setup for each environment
- Development
- Staging
- Production
.env.development
Load environment-specific config
app.config.js
Build with environment
EAS Build Configuration
Configure eas.json
eas.json
Store secrets in EAS
eas.json
Secrets prefixed with
@ are read from EAS Secret Storage.Type-Safe Configuration
Define types
types/env.d.ts
Create config object
utils/config.ts
Validate on startup
app/_layout.tsx
Runtime vs Build-time
Build-time configuration
Evaluated when building your app:app.config.js
Runtime configuration
Available in your JavaScript code:Security Best Practices
Don’t commit secrets
.gitignore
Provide example file
.env.example
Separate public and private
Use EAS Secrets for sensitive data
Advanced Patterns
Dynamic configuration
utils/config.ts
Feature flags
utils/features.ts
Remote configuration
Fetch configuration from a server at runtime:utils/remoteConfig.ts
Debugging
Log configuration
Validation helper
utils/validateEnv.ts
Troubleshooting
Environment variables not updating
Environment variables not updating
Variables undefined in app
Variables undefined in app
- Ensure variables are prefixed with
EXPO_PUBLIC_ - Check .env file is in project root
- Restart dev server after changing .env
- Verify dotenv is installed and configured
Different values in development vs build
Different values in development vs build
Check which environment file is being loaded:
Best Practices
- Prefix public variables: Use
EXPO_PUBLIC_for client-accessible variables - Never commit secrets: Add .env files to .gitignore
- Provide .env.example: Document required variables
- Use EAS Secrets: Store sensitive build-time secrets in EAS
- Validate on startup: Check required variables are present
- Type your config: Use TypeScript for type-safe configuration
- Separate by environment: Use different files for dev/staging/prod
- Document variables: Comment what each variable is for
- Use sensible defaults: Provide fallback values where appropriate
- Keep secrets on backend: Don’t embed API secrets in your app