xref: /expo/docs/pages/workflow/configuration.mdx (revision a16ac082)
1---
2title: Configure with app.json/app.config.js
3description: Learn about what is app config and how you can dynamically use it by customizing it.
4---
5
6import PossibleRedirectNotification from '~/components/plugins/PossibleRedirectNotification';
7import { Terminal } from '~/ui/components/Snippet';
8
9<PossibleRedirectNotification newUrl="/versions/latest/config/app/" />
10
11The app config (**app.json**, **app.config.js**, **app.config.ts**) is used for configuring how a project loads in [Expo Go](/get-started/expo-go/), [Expo Prebuild](/workflow/prebuild) generation, and the OTA update manifest. You can think of this as an `index.html` but for React Native apps.
12
13It must be located at the root of your project, next to the **package.json**. Here is a bare-minimum example:
14
15```json
16{
17  "expo": {
18    "name": "My app",
19    "slug": "my-app"
20  }
21}
22```
23
24Most configuration from the app config is accessible at runtime from the JavaScript code using [`Constants.expoConfig`](/versions/latest/sdk/constants/#nativeconstants--properties). Sensitive information such as secret keys are removed.
25
26## Properties
27
28The 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 reference](/versions/latest/config/app/).
29
30> **info** Do you use Visual Studio Code? If so, we recommend that you install the [vscode-expo](https://marketplace.visualstudio.com/items?itemName=expo.vscode-expo-tools) extension to get auto-completion of properties in **app.json** files.
31
32## Extending configuration
33
34Library authors can extend the app config by using [Expo Config plugins](/config-plugins/introduction/).
35
36> **info** Config plugins are mostly used to configure the [`npx expo prebuild`](/workflow/prebuild) command.
37
38## Dynamic configuration
39
40For more customization, you can use the JavaScript or [TypeScript](#using-typescript-for-configuration-appconfigts-instead-of) (**app.config.js**, or **app.config.ts**). These configs have the following properties:
41
42- Comments, variables, and single quotes.
43- Importing/requiring other JavaScript files. Using import/export syntax in external files is not supported. All imported files must be transpiled to support your current version of Node.js.
44- TypeScript support with nullish coalescing and optional chaining.
45- Updated whenever Metro bundler reloads.
46- Provide environment information to your app.
47- Does not support Promises.
48
49For example, you can export an object to define your custom config:
50
51```js app.config.js
52const myValue = 'My App';
53
54module.exports = {
55  name: myValue,
56  version: process.env.MY_CUSTOM_PROJECT_VERSION || '1.0.0',
57  // All values in extra will be passed to your app.
58  extra: {
59    fact: 'kittens are cool',
60  },
61};
62```
63
64The `"extra"` key allows passing arbitrary configuration data to your app. The value of this key is accessed using [`expo-constants`](/versions/latest/sdk/constants/):
65
66```js App.js
67import Constants from 'expo-constants';
68
69Constants.expoConfig.extra.fact === 'kittens are cool';
70```
71
72You 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**.
73
74For example, your **app.json** could look like this:
75
76```json app.json
77{
78  "expo": {
79    "name": "My App"
80  }
81}
82```
83
84And in your **app.config.js**, you are provided with that configuration in the arguments to the exported function:
85
86```js app.config.js
87module.exports = ({ config }) => {
88  console.log(config.name); // prints 'My App'
89  return {
90    ...config,
91  };
92};
93```
94
95### Switching configuration based on the environment
96
97It'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.
98
99```js app.config.js
100module.exports = () => {
101  if (process.env.MY_ENVIRONMENT === 'production') {
102    return {
103      /* your production config */
104    };
105  } else {
106    return {
107      /* your development config */
108    };
109  }
110};
111```
112
113To 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:
114
115<Terminal cmd={['$ MY_ENVIRONMENT=production eas update']} />
116
117This is not anything unique to Expo CLI. On Windows you can approximate the above command with:
118
119<Terminal cmd={['$ npx cross-env MY_ENVIRONMENT=production eas update']} />
120
121Or you can use any other mechanism that you are comfortable with for environment variables.
122
123### Using TypeScript for configuration: app.config.ts instead of app.config.js
124
125You can use autocomplete and doc-blocks with an Expo config in TypeScript. Create an **app.config.ts** with the following contents:
126
127```ts app.config.ts
128import { ExpoConfig, ConfigContext } from 'expo/config';
129
130export default ({ config }: ConfigContext): ExpoConfig => ({
131  ...config,
132  slug: 'my-app',
133  name: 'My App',
134});
135```
136
137If you want to import other TypeScript files or customize the language features, we recommend using `ts-node` as described in [Using TypeScript](/guides/typescript#appconfigjs).
138
139### Configuration resolution rules
140
141There 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.
142
1431. The static config is read if **app.config.json** exists (falls back to **app.json**). If no static config exists, then default values are inferred from the **package.json** and your dependencies.
1442. The dynamic config is read if either **app.config.ts** or **app.config.js** exist. If both exist, then the TypeScript config is used.
1453. If the dynamic config returns a function, then the static config is passed to the function with `({ config }) => ({})`. This function can then mutate the static config values. Think of this like middleware for the static config.
1464. The return value from the dynamic config is used as the final config. It cannot have any promises.
1475. All functions in the config are evaluated and serialized before any tool in the Expo ecosystem uses it. The config must be a JSON manifest when it is hosted.
148