Edit this page
Learn how to use environment variables in your project.
An Expo Router web project may include client-side and server-side environment variables. The client-side environment variables are embedded in the app and inlined in the JavaScript bundle when you run npx expo export
. The server-side environment variables are kept securely on the server and are deployed with the API routes code when you run eas deploy
.
With EAS environment variables, only plain text and sensitive environment variables can be used. Secrets cannot be deployed with EAS Hosting.
All the 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_
.
Then, when you run npx expo export
, all instances of process.env.EXPO_PUBLIC_*
environment variables will be replaced with values from the environment.
All the code in your API routes (that is, files that end with +api.ts) runs on the server.
Since the code running on the server is never visible to the app user, the server-side code can safely use sensitive environment variables such as API keys and tokens.
Unlike client-side environment variables, server-side environment variables are not inlined in the code, they are uploaded with the deployment when you run the eas deploy
command.
For local development, both server- and client-side environment variables are loaded from a local .env file, which should be gitignored. If you're using EAS environment variables, use eas env:pull
to retrieve the environment variables for development
, preview
, or production
.
The two primary ways of handling environment variables are via EAS environment variables or .env files.
With EAS environment variables, you store all variables in EAS using the EAS CLI or the web UI and pull them down locally as and when necessary.
When using the EAS environment variables, use the eas env:pull
command to pull down the environment you want to develop against.
For deploying a project with environment variables, note that the environment variables for the client- and server-side code are included at different steps:
npx expo export --platform web
will inline the EXPO_PUBLIC_
variables in the frontend code. So ensure that your .env or .env.local file includes the correct environment variables before running the export command.eas deploy --environment production
will include all variables for the given environment (in this case, production
) in the API routes. EAS Environment variables loaded with the --environment
flag 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.