2022-09-13 12:54:31 +00:00
---
2022-10-06 09:15:30 +00:00
navigation.icon: IconFile
2022-09-13 12:54:31 +00:00
title: app.config.ts
2022-11-21 15:51:39 +00:00
head.title: 'app.config.ts'
2022-10-06 09:15:30 +00:00
description: Nuxt 3 provides the app.config file to expose reactive configuration within your application.
2022-09-13 12:54:31 +00:00
---
# App Config File
2022-08-17 15:23:13 +00:00
Nuxt 3 provides an `app.config` config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).
2022-09-13 12:54:31 +00:00
You can easily provide runtime app configuration using `app.config.ts` file. It can have either of `.ts` , `.js` , or `.mjs` extensions.
```ts [app.config.ts]
export default defineAppConfig({
foo: 'bar'
})
```
2022-08-17 15:23:13 +00:00
::alert{type=warning}
Do not put any secret values inside `app.config` file. It is exposed to the user client bundle.
::
## Defining App Config
To expose config and environment variables to the rest of your app, you will need to define configuration in `app.config` file.
**Example:**
```ts [app.config.ts]
export default defineAppConfig({
theme: {
primaryColor: '#ababab'
}
})
```
2022-11-16 10:04:28 +00:00
When adding `theme` to the `app.config` , Nuxt uses Vite or webpack to bundle the code. We can universally access `theme` in both server and browser using [useAppConfig ](/docs/api/composables/use-app-config ) composable.
2022-08-17 15:23:13 +00:00
```js
const appConfig = useAppConfig()
console.log(appConfig.theme)
```
### Manually Typing App Config
2023-02-04 14:29:33 +00:00
Nuxt tries to automatically generate a TypeScript interface from provided app config.
It is also possible to type app config manually. There are two possible things you might want to type.
#### Typing App Config Input
2022-08-17 15:23:13 +00:00
2023-02-04 14:29:33 +00:00
`AppConfigInput` might be used by module authors who are declaring what valid _input_ options are when setting app config. This will not affect the type of `useAppConfig()` .
2022-08-17 15:23:13 +00:00
```ts [index.d.ts]
declare module '@nuxt/schema' {
2022-09-06 16:15:27 +00:00
interface AppConfigInput {
2022-08-17 15:23:13 +00:00
/** Theme configuration */
2022-09-06 16:15:27 +00:00
theme?: {
2022-08-17 15:23:13 +00:00
/** Primary app color */
2022-09-06 16:15:27 +00:00
primaryColor?: string
2022-08-17 15:23:13 +00:00
}
}
}
// It is always important to ensure you import/export something when augmenting a type
export {}
```
2023-02-04 14:29:33 +00:00
#### Typing App Config Output
If you want to type the result of calling `useAppConfig()` , then you will want to extend `AppConfig` .
::alert{type=warning}
Be careful when typing `AppConfig` as you will overwrite the types Nuxt infers from your actually defined app config.
::
```ts [index.d.ts]
declare module '@nuxt/schema' {
interface AppConfig {
// This will entirely replace the existing inferred `theme` property
theme: {
// You might want to type this value to add more specific types than Nuxt can infer,
// such as string literal types
primaryColor?: 'red' | 'blue'
}
}
}
// It is always important to ensure you import/export something when augmenting a type
export {}
```