Skip to main content
Environment variables allow you to customize your app’s behavior based on the environment (development, staging, production) without changing code.

Types of Environment Variables

Expo supports two types of environment variables:
  1. Build-time variables - Available during app configuration and bundling
  2. Runtime variables - Available in your app code at runtime

EXPO_PUBLIC Variables

Variables prefixed with EXPO_PUBLIC_ are embedded in your JavaScript bundle and available at runtime.

Setting EXPO_PUBLIC Variables

Create a .env file in your project root:
.env

Accessing at Runtime

Access these variables directly in your code:
Example in a React component:

Important Notes

  • Variables must be prefixed with EXPO_PUBLIC_
  • They are embedded in your JavaScript bundle
  • They are visible in your published code
  • Never use them for secrets or sensitive data
  • Changes require restarting the dev server

Build-Time Variables

Variables without the EXPO_PUBLIC_ prefix are only available during configuration and bundling.

In App Configuration

Use in app.config.js:
app.config.js

Accessing Build-Time Variables

Through expo-constants:

.env Files

Expo CLI automatically loads environment variables from .env files.

File Priority

Expo loads .env files in this order (later files override earlier):
  1. .env - Default for all environments
  2. .env.local - Local overrides (git ignored)
  3. .env.${ENV} - Environment-specific (e.g., .env.production)
  4. .env.${ENV}.local - Local environment overrides

Example Setup

Create multiple .env files:
.env
.env.development
.env.production
.env.local

Specifying Environment

Set the ENV variable to load specific files:

.gitignore

Don’t commit sensitive files:
.gitignore
Create a template:
.env.example

Setting Variables

Command Line

Set variables inline:
Multiple variables:

Shell Configuration

Add to your shell profile (.bashrc, .zshrc):

Cross-Platform Scripts

Use cross-env for Windows compatibility: Install:
Use in package.json:

CI/CD Environments

GitHub Actions

Set environment variables in workflows:
.github/workflows/build.yml
Store secrets in GitHub repository settings.

GitLab CI

.gitlab-ci.yml

EAS Build

Use eas.json:
eas.json
Or use EAS Secrets:

Expo CLI Environment Variables

Expo CLI itself uses environment variables for configuration:

Common CLI Variables

boolean
Enable debug logging: EXPO_DEBUG=1
boolean
Skip network requests: EXPO_OFFLINE=1
boolean
Run in non-interactive CI mode: CI=1
boolean
Disable analytics: EXPO_NO_TELEMETRY=1
boolean
Disable API caches: EXPO_NO_CACHE=1
number
Metro bundler port: PORT=8082

Metro Configuration

boolean
Disable lazy bundling: EXPO_NO_METRO_LAZY=1
string
Path to custom Metro config: EXPO_OVERRIDE_METRO_CONFIG=./metro.custom.js

Development Features

string
Default editor to open: EXPO_EDITOR=code
boolean
Enable bundle analysis: EXPO_ATLAS=1
string
Log debug events: LOG_EVENTS=1 or LOG_EVENTS=events.log

Security Best Practices

Never Commit Secrets

Don’t put sensitive data in:
  • Version control
  • EXPO_PUBLIC variables
  • Client-side code

Use Backend APIs

Store secrets on your backend:

Validate on Server

Never trust client-provided values:

Rotate Secrets

Regularly rotate API keys and tokens:
  1. Generate new secrets
  2. Update environment variables
  3. Rebuild and deploy app
  4. Revoke old secrets

Common Patterns

Feature Flags

Control features with environment variables:

Environment Detection

Detect current environment:

API Configuration

Configure APIs per environment:

Troubleshooting

Variables Not Available

If variables aren’t working:
  1. Check prefix: Must start with EXPO_PUBLIC_
  2. Restart dev server: Changes require restart
  3. Check .env file: Must be in project root
  4. Verify file name: Exact match (.env, not env.txt)

Variables Undefined at Runtime

Build-Time vs Runtime

Build-time variables won’t update without rebuilding:

CI/CD Not Working

Ensure environment variables are set in CI:

TypeScript Support

Add type definitions:
env.d.ts
Use with type safety: