> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nuxt/nuxt/llms.txt
> Use this file to discover all available pages before exploring further.

# Programmatic Usage

> Programmatic utilities for working with Nuxt

# Programmatic Usage

Nuxt Kit provides a set of utilities to help you work with Nuxt programmatically. These functions allow you to load Nuxt, build Nuxt, and load Nuxt configuration.

Programmatic usage can be helpful when you want to use Nuxt programmatically, for example, when building a CLI tool or test utils.

## `loadNuxt`

Load Nuxt programmatically. It will load the Nuxt configuration, instantiate and return the promise with Nuxt instance.

### Type

```ts theme={null}
function loadNuxt(loadOptions?: LoadNuxtOptions): Promise<Nuxt>
```

### Parameters

**`loadOptions`**: Loading conditions for Nuxt. `loadNuxt` uses `c12` under the hood, so it accepts the same options with some additional options:

| Property | Type      | Required | Description                                                                                                         |
| -------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
| `dev`    | `boolean` | `false`  | If set to `true`, Nuxt will be loaded in development mode.                                                          |
| `ready`  | `boolean` | `true`   | If set to `true`, Nuxt will be ready to use after the `loadNuxt` call. If `false`, you need to call `nuxt.ready()`. |

### Usage

```ts theme={null}
import { loadNuxt } from '@nuxt/kit'

const nuxt = await loadNuxt({
  dev: process.env.NODE_ENV !== 'production',
})
```

## `buildNuxt`

Build Nuxt programmatically. It will invoke the builder (currently `@nuxt/vite-builder` or `@nuxt/webpack-builder`) to bundle the application.

### Type

```ts theme={null}
function buildNuxt(nuxt: Nuxt): Promise<any>
```

### Parameters

**`nuxt`**: Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.

### Usage

```ts theme={null}
import { buildNuxt, loadNuxt } from '@nuxt/kit'

const nuxt = await loadNuxt({
  dev: false,
})

await buildNuxt(nuxt)
```

## `loadNuxtConfig`

Load Nuxt configuration. It will return the promise with the configuration object.

### Type

```ts theme={null}
function loadNuxtConfig(options: LoadNuxtConfigOptions): Promise<NuxtOptions>
```

### Parameters

**`options`**: Options to pass in `c12` `loadConfig` call.

### Usage

```ts theme={null}
import { loadNuxtConfig } from '@nuxt/kit'

const config = await loadNuxtConfig({
  cwd: process.cwd(),
})

console.log(config)
```

## `writeTypes`

Generates `tsconfig.json` and writes it to the project buildDir.

### Type

```ts theme={null}
function writeTypes(nuxt?: Nuxt): void
```

### Parameters

**`nuxt`**: Nuxt instance to build. It can be retrieved from the context via `useNuxt()` call.

### Usage

```ts theme={null}
import { loadNuxt, writeTypes } from '@nuxt/kit'

const nuxt = await loadNuxt({
  dev: process.env.NODE_ENV !== 'production',
})

writeTypes(nuxt)
```

## Source

[View source on GitHub](https://github.com/nuxt/nuxt/tree/main/packages/kit/src/loader)
