This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Using environment variables in Expo Services
Edit page
Learn how to use environment variables in builds, updates, hosting, and workflow jobs with Expo Services.
The following sections cover how to use environment variables in builds, updates, and workflow jobs with Expo Services.
Using environment variables with Expo Build
To have full control over the environments used for your builds, you can specify the environment field in the build profiles settings in the eas.json file.
All of the environment variables from the selected environment will be used during the build process. Plain text and sensitive variables will be available when resolving build configuration based on the dynamic app config in EAS CLI as well.
If you don't set the environment option, we will set the environment automatically based on your build's configuration:
productionwhendistributionis set tostoredevelopmentwhendevelopmentClientistruepreviewfor everything else
Built-in environment variables
The following environment variables are additional system environment variables exposed to each job and can be used within any build step. They are not a part of any project environment and are not available when evaluating app.config.js locally:
CI=1: Indicates this is a CI environmentEAS_BUILD=true: Indicates this is an Expo Build environmentEAS_BUILD_PLATFORM: EitherandroidoriosEAS_BUILD_RUNNER: Eithereas-buildfor Expo Build cloud builds orlocal-build-pluginfor local buildsEAS_BUILD_ID: The build ID, for example,f51831f0-ea30-406a-8c5f-f8e1cc57d39cEAS_BUILD_PROFILE: The name of the build profile from eas.json, for example,productionEAS_BUILD_PROJECT_ID: the Expo Services project ID, for example,bd2f7e21-1ee7-47f2-8357-d7c4b50622fbEAS_BUILD_GIT_COMMIT_HASH: The hash of the Git commit, for example,88f28ab5ea39108ade978de2d0d1adeedf0ece76EAS_BUILD_NPM_CACHE_URL: The URL of npm cache (learn more about private npm packages)EAS_BUILD_MAVEN_CACHE_URL: The URL of Maven cache (learn more about caching Android dependencies)EAS_BUILD_COCOAPODS_CACHE_URL: The URL of CocoaPods cache (learn more about caching iOS dependencies)EAS_BUILD_USERNAME: The username of the user initiating the build (it's undefined for bot users)EAS_BUILD_WORKINGDIR: The remote directory path with your projectEAS_BUILD_DISABLE_BUNDLE_JAVASCRIPT_STEP: Set to1to skip the early JavaScript bundling check. By default, Expo Build runs the JavaScript bundler before the native build to surface JS errors earlier. Disabling this step means JavaScript errors won't be caught until the native build step.EAS_BUILD_DISABLE_NPM_CACHE: Set to1to disable the npm cache server (learn more about caching JavaScript dependencies)EAS_BUILD_DISABLE_MAVEN_CACHE: Set to1to disable the Maven cache server (learn more about caching Android dependencies)EAS_BUILD_DISABLE_COCOAPODS_CACHE: Set to1to disable the CocoaPods cache server (learn more about caching iOS dependencies)
The environment variables of secret type are not available during build configuration resolution in EAS CLI as they are not readable outside of the Expo servers.
Using environment variables with Expo Update
In SDK 55 or later, the --environment flag is required when running eas update. The environment variables from the specified Expo Services environment will be used during the update process. For projects using SDK 54 or earlier, eas update falls back to local .env files when the --environment flag is omitted.
To use Expo Services environment variables with Expo Update, run the eas update command with the --environment flag:
When the --environment flag is used, only the environment variables from the specified Expo Services environment will be used during the update process and won't use the .env files present in your project. This ensures the same environment variables are used for both your updates and builds.
Expo CLI will substitute prefixed variables in your code (for example, process.env.EXPO_PUBLIC_VARNAME) with the corresponding plain text and sensitive environment variable values set on Expo servers for the environment specified with the --environment flag. Any EXPO_PUBLIC_ variables in your application code will be replaced inline with the corresponding values from your Expo Services environment whether that is your local machine or your CI/CD server.
The --environment flag ensures the same environment variables are used for both your update and build jobs.
The secret variables will not be available during the update process as they are not readable outside of Expo servers.
Using environment variables with Expo Hosting
An Expo Router web project can include environment variables that are used on both the client and the server. Client-side values are inlined in the JavaScript bundle when you run npx expo export, while server-side values are stored on the server and are deployed with your API routes when you run eas deploy.
With Expo Hosting, only plain text and sensitive environment variables can be used. Secrets cannot be deployed with Expo Hosting.
Client-side environment variables
All code that runs in the browser is client-side. In an Expo Router project, this includes all code that is not an API Route or server function. The environment variables in your client-side code are inlined at build time. You should never put any sensitive information in your client-side code, which is why all client-side environment variables must be prefixed with EXPO_PUBLIC_.
When you run npx expo export, all instances of process.env.EXPO_PUBLIC_* environment variables will be replaced with values from the environment.
Server-side environment variables
All the code in your API routes (files ending with +api.ts) runs on the server. Since the code running on the server is never visible to the app user, you can safely use sensitive environment variables such as API keys and tokens.
Server-side environment variables are not inlined in the code, they are uploaded with the deployment when you run the eas deploy command.
Storing environment variables
When deploying a project with Expo Services environment variables, note that the environment variables for the client-side and server-side code are included at different steps:
- Running
npx expo export --platform webwill inline theEXPO_PUBLIC_variables in the frontend code. So ensure that your .env.local file includes the correct environment variables before running thenpx expo exportcommand. eas deploy --environment productionwill include all variables for the given environment (in this case,production) in the API routes. Expo Services environment variables loaded with the--environmentflag will take precedence over ones defined in .env and .env.local files.
Environment variables are per deployment, and deployments are immutable. This means that after changing an environment variable, you will need to re-export your project, and re-deploy in order for them to be updated.
For local development
For local development, both client- and server-side environment variables are loaded from local .env files, which should be gitignored. If you are using Expo Services environment variables, use eas env:pull to retrieve the environment variables for development, preview, or production.
Using environment variables for other commands
One way to supply non-secret Expo Services environment variables to other EAS CLI commands is to use the eas env:exec command.
For example, it can be useful when uploading source maps to Sentry using a SENTRY_AUTH_TOKEN variable after an update bundle is created.
Using environment variables in Expo Workflows
Setting Expo Services environment for workflow jobs
When you omit jobs.<job_id>.environment, the default depends on the job type:
- Build jobs: The environment comes from the build profile in eas.json (
build.<profile>.environment). If that field is missing, the automatic defaults described above apply. Using environment variables with Expo Build. - Submit jobs: The environment is inherited from the submitted build.
- Maestro jobs (
maestroandmaestro-cloud): The environment defaults topreview. - Other jobs (for example, update, fingerprint, deploy, and custom jobs): The environment defaults to
production.
Set environment explicitly on a job to override its default and keep it in sync with the build profile you used earlier in the workflow. For a full explanation, see The job environment.
In the following example, a build job is configured to use the preview profile, then an update job is configured to use the same Expo Services environment.
In the following example, a fingerprint job is configured to use the production environment, then a build job is configured to use the same Expo Services environment.
Keep the job environment value in sync with the build profile to avoid mismatched secrets. For example, fingerprint/update jobs should usually match the build's profile environment.
Dynamically setting environment variables during the job execution
You can also set environment variables dynamically during the job execution using the set-env command.
The set-env executable is available in the PATH on Expo Build workers, and can be used to set environment variables that will be visible in the next build phases.
For example, you can add the following in one of the Expo Build hooks and the environment variable EXAMPLE_ENV will be available until the end of the build job.
Accessing environment variables
After creating an environment variable, you can read it on subsequent Expo Build jobs with process.env.VARIABLE_NAME from Node.js or in shell scripts as $VARIABLE_NAME.