Skip to main content

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:
Never put sensitive secrets in EXPO_PUBLIC_* variables. They’re embedded in your app bundle and can be extracted by users.

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

.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
Usage:

Remote configuration

Fetch configuration from a server at runtime:
utils/remoteConfig.ts

Debugging

Log configuration

Validation helper

utils/validateEnv.ts
Call on app start:

Troubleshooting

  • 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
Check which environment file is being loaded:
Always restart your development server after modifying .env files. Environment variables are loaded at startup.

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