Learn about what app.json/app.config.js/app.config.ts files are and how you can customize and use them dynamically.
The app config (app.json, app.config.js, app.config.ts) is used for configuring Expo Prebuild generation, how a project loads in Expo Go, and the OTA update manifest. You can think of this as an index.html but for React Native apps.
It must be located at the root of your project, next to the package.json. Here is a bare-minimum example:
{
"expo": {
"name": "My app",
"slug": "my-app"
}
}
Most configuration from the app config is accessible at runtime from the JavaScript code using Constants.expoConfig
. Sensitive information such as secret keys are removed.
The app config configures many things such as app name, icon, splash screen, deep linking scheme, API keys to use for some services and so on. For a complete list of available properties, see app.json/app.config.js/app.config.ts reference.
Do you use Visual Studio Code? If so, we recommend that you install the Expo Tools extension to get auto-completion of properties in app.json files.
Library authors can extend the app config by using Expo Config plugins.
Config plugins are mostly used to configure thenpx expo prebuild
command.
For more customization, you can use the JavaScript (app.config.js) or TypeScript (app.config.ts). These configs have the following properties:
For example, you can export an object to define your custom config:
const myValue = 'My App';
module.exports = {
name: myValue,
version: process.env.MY_CUSTOM_PROJECT_VERSION || '1.0.0',
// All values in extra will be passed to your app.
extra: {
fact: 'kittens are cool',
},
};
The "extra"
key allows passing arbitrary configuration data to your app. The value of this key is accessed using expo-constants
:
import Constants from 'expo-constants';
Constants.expoConfig.extra.fact === 'kittens are cool';
You can access and modify incoming config values by exporting a function that returns an object. This is useful if your project also has an app.json. By default, Expo CLI will read the app.json first and send the normalized results to the app.config.js.
For example, your app.json could look like this:
{
"expo": {
"name": "My App"
}
}
And in your app.config.js, you are provided with that configuration in the arguments to the exported function:
module.exports = ({ config }) => {
console.log(config.name); // prints 'My App'
return {
...config,
};
};
It's common to have some different configuration in development, staging, and production environments, or to swap out configuration entirely to white label an app. To accomplish this, you can use app.config.js along with environment variables.
module.exports = () => {
if (process.env.MY_ENVIRONMENT === 'production') {
return {
/* your production config */
};
} else {
return {
/* your development config */
};
}
};
To use this configuration with Expo CLI commands, set the environment variable either for specific commands or in your shell profile. To set environment variables for specific commands, prefix the command with the variables and values as shown in the example:
-
MY_ENVIRONMENT=production eas update
This is not anything unique to Expo CLI. On Windows you can approximate the above command with:
-
npx cross-env MY_ENVIRONMENT=production eas update
Or you can use any other mechanism that you are comfortable with for environment variables.
You can use autocomplete and doc-blocks with an Expo config in TypeScript. Create an app.config.ts with the following contents:
import { ExpoConfig, ConfigContext } from 'expo/config';
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
slug: 'my-app',
name: 'My App',
});
If you want to import other TypeScript files or customize the language features, we recommend using ts-node
as described in Using TypeScript.
There are two different types of configs: static (app.config.json, app.json), and dynamic (app.config.js, app.config.ts). Static configs can be automatically updated with CLI tools, whereas dynamic configs must be manually updated by the developer.
({ config }) => ({})
. This function can then mutate the static config values. Think of this like middleware for the static config.