Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 38 ยท EAS Build and Updates

App Config and Environment Variables

Configure an Expo app with app.json and dynamic app.config.js: build variants, EXPO_PUBLIC_ variables, .env files, EAS environment variables, secrets and config plugins.

Every Expo app has a configuration: its name, icon, bundle identifier, permissions, plugins, splash screen. Expo reads it from app.json, or from app.config.js / app.config.ts when you need logic, such as a different app name and identifier for the staging build.

This lesson covers the config file itself, how to make variants (one codebase, several installable apps) and how to handle environment variables and secrets without leaking them.

What runs on this site. app.config.js is plain JavaScript, so the stand-ins below run it for real in Node.js. Only the build and the native apps are read-only.

Static config: app.json

JSON
{
  "expo": {
    "name": "Habit Hero",
    "slug": "habit-hero",
    "version": "1.2.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "scheme": "habithero",
    "ios": { "bundleIdentifier": "com.example.habithero" },
    "android": { "package": "com.example.habithero" },
    "plugins": ["expo-router", "expo-secure-store"],
    "extra": { "eas": { "projectId": "00000000-0000-0000-0000-000000000000" } }
  }
}

Important keys:

  • slug is the project's URL name on expo.dev; scheme enables deep links (habithero://notes/3).
  • ios.bundleIdentifier and android.package are the permanent identity of your app in the stores. Choose carefully; changing them later makes a different app.
  • plugins are config plugins: small functions that edit the native iOS and Android projects during prebuild (adding permissions, entitlements, native libraries). Most Expo packages ship one.
  • extra is a free-form bag; read it at runtime with Constants.expoConfig.extra.

Dynamic config: app.config.js

When a file named app.config.js exists, Expo runs it and uses what it returns. It receives the contents of app.json as config, so you extend instead of repeat:

JavaScript
// app.config.js
const IS_DEV = process.env.APP_VARIANT === 'development';
const IS_PREVIEW = process.env.APP_VARIANT === 'preview';

const suffix = IS_DEV ? '.dev' : IS_PREVIEW ? '.preview' : '';

module.exports = ({ config }) => ({
  ...config,
  name: IS_DEV ? 'Habit Hero (Dev)' : IS_PREVIEW ? 'Habit Hero (Preview)' : config.name,
  ios: { ...config.ios, bundleIdentifier: config.ios.bundleIdentifier + suffix },
  android: { ...config.android, package: config.android.package + suffix },
});
Node.js Run a config function (this is real JavaScript)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Because each variant has a different identifier, a tester can install the development, preview and production apps side by side on one phone. Set APP_VARIANT in each profile's env in eas.json (previous lesson).

The two kinds of environment variables

Environment variables are values outside your code that change per environment (staging vs production). In an Expo app they come in two very different kinds:

Build-time config Public runtime values
Where they are read In app.config.js, by Node, while building In your app code
How process.env.APP_VARIANT process.env.EXPO_PUBLIC_API_URL
Visible to the user? Only if you copy them into extra Yes, inlined into the bundle

Expo replaces process.env.EXPO_PUBLIC_* references with their literal values when it bundles. Variables without that prefix are not available inside your app code.

Terminal
# .env            (committed: safe defaults only)
EXPO_PUBLIC_API_URL=http://localhost:3000

# .env.local      (not committed: your personal overrides)
EXPO_PUBLIC_API_URL=http://192.168.1.20:3000
JavaScript
const api = process.env.EXPO_PUBLIC_API_URL;     // good: inlined
const { EXPO_PUBLIC_API_URL } = process.env;     // wrong: destructuring is NOT inlined
const e = process.env; e.EXPO_PUBLIC_API_URL;    // wrong: dynamic access is not inlined

Always write the full process.env.EXPO_PUBLIC_NAME expression.

Public does not mean secret

Whatever you put in an EXPO_PUBLIC_ variable, or in extra, ships inside the app. Anyone can unzip an app and read it. Fine to put there: API base URLs, public analytics keys, a Maps key that is restricted by app. Never put there: database passwords, private API keys, signing secrets. Keep those on your server and let the app call your server.

EAS environment variables

For values used while building (in app.config.js, or by native build steps), EAS offers hosted variables, managed with the CLI or at expo.dev:

Terminal
eas env:create --name SENTRY_AUTH_TOKEN --value "..." --environment production --visibility secret
eas env:list --environment production
eas env:pull --environment development   # writes .env.local for local use

Visibility levels:

  • plain text: visible in logs and the dashboard (for non-sensitive config).
  • sensitive: hidden in logs, readable by your team in the dashboard.
  • secret: write-only after creation; only builds can use it.

A profile in eas.json picks the environment: "production": { "environment": "production" }.

Node.js Which values would a user be able to read?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Reading config at runtime

JSX
import Constants from 'expo-constants';

const { version, extra } = Constants.expoConfig;
const projectId = extra.eas.projectId;
console.log(Constants.expoConfig.name, version);

Constants.expoConfig is the resolved config embedded at build time, so values computed in app.config.js (for example extra.apiUrl) are available here. For the installed app version and build number, use expo-application (Application.nativeApplicationVersion).

Prebuild and native folders

npx expo prebuild generates the ios/ and android/ folders from your config and plugins. This is called Continuous Native Generation: those folders are build output, not source. Many teams add them to .gitignore and let EAS generate them on every build. If you change app.json or plugins, re-run prebuild (with --clean) and rebuild the development client. If you edit the native folders by hand, you move into the "bare" workflow and give up regeneration, so prefer writing a config plugin instead.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why would you use app.config.js instead of app.json?

    app.config.js runs as code, so it can read environment variables and branch.
  2. 2. Which variable is available inside your app code?

    Only EXPO_PUBLIC_ variables are inlined into the bundle. APP_VARIANT is for build-time config.
  3. 3. Which line is NOT inlined by Expo?

    Destructuring and dynamic access are not replaced; the full dotted expression is required.
  4. 4. Why give each variant a different bundle identifier?

    Different identifiers make different apps on the device.

Summary

  • Configure the app in app.json, or app.config.js for logic and variants.
  • Use APP_VARIANT (set per EAS profile) to change names and identifiers.
  • EXPO_PUBLIC_* values are inlined into the bundle and are public; never put secrets there.
  • Build-time secrets go into EAS environment variables with secret visibility.
  • prebuild generates the native projects from config and plugins.

Next: Submitting to the stores