Using environment variables without EAS

Edit page

Learn about non-EAS ways to manage environment variables in Expo and React Native projects.


Using EAS Environment Variables is the recommended way to manage environment variables for cloud builds and updates, but you can still work locally or with other tooling.

Managing environment variables without EAS

If you want to manage environment variables without EAS, you can use tools like dotenv (Node-based loaders) or services such as Doppler that inject environment variables. These utilities allow you to create a .env file in which you can store your environment variables.

Note: Avoid committing secrets to .env files if you are managing your environment variables without EAS.

How environment variables are loaded

After creating the .env file, you need to ensure that the file is not listed inside your .gitignore or .easignore files. Then it can be picked by EAS commands like eas build, eas update, and so on.

The .env files load according to the standard .env file resolution and then replaces all references in your code to process.env.EXPO_PUBLIC_[VARIABLE_NAME] with the corresponding value set in the .**env **files. Code inside node_modules directory is not affected for security purposes.

Reading environment variables from .env files

For more information, see how to read environment variables from .env files in Expo CLI.

Using .env files with EAS Hosting

When using .env files with EAS Hosting, environment variables prefixed with EXPO_PUBLIC_ are all available in the client-side code and the server-side code. The variables not prefixed with EXPO_PUBLIC_ are only available in the server-side code.

The steps for including client-side and server-side environment variables are the same as when using EAS environment variables. So you need to ensure that your local .env files include the correct environment variables before running the npx export command.