# Import a YAML file (/docs/guides/runtime/import-yaml)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 474 · updated: 2026-07-28 -->
Related: [Delete directories](/docs/guides/runtime/delete-directory.md), [Delete files](/docs/guides/runtime/delete-file.md), [Import a HTML file as text](/docs/guides/runtime/import-html.md), [Import a JSON file](/docs/guides/runtime/import-json.md), [Import a JSON5 file](/docs/guides/runtime/import-json5.md), [Import a TOML file](/docs/guides/runtime/import-toml.md)

Bun natively supports `.yaml` and `.yml` imports.

```yaml config.yaml icon="file-code"
database:
  host: localhost
  port: 5432
  name: myapp

server:
  port: 3000
  timeout: 30

features:
  auth: true
  rateLimit: true
```

***

Import the file like any other source file.

```ts config.ts icon="/icons/typescript.svg"
import config from "./config.yaml";

config.database.host; // => "localhost"
config.server.port; // => 3000
config.features.auth; // => true
```

***

You can also destructure top-level properties with named imports:

```ts config.ts icon="/icons/typescript.svg"
import { database, server, features } from "./config.yaml";

console.log(database.name); // => "myapp"
console.log(server.timeout); // => 30
console.log(features.rateLimit); // => true
```

***

Bun also supports [Import Attributes](https://github.com/tc39/proposal-import-attributes) syntax:

```ts config.ts icon="/icons/typescript.svg"
import config from "./config.yaml" with { type: "yaml" };

config.database.port; // => 5432
```

***

For parsing YAML strings at runtime, use `Bun.YAML.parse()`:

```ts config.ts icon="/icons/typescript.svg"
const yamlString = `
name: John Doe
age: 30
hobbies:
  - reading
  - coding
`;

const data = Bun.YAML.parse(yamlString);
console.log(data.name); // => "John Doe"
console.log(data.hobbies); // => ["reading", "coding"]
```

***

## TypeScript Support [#typescript-support]

To add TypeScript support for your YAML imports, create a declaration file with `.d.ts` appended to the YAML filename (for example, `config.yaml` → `config.yaml.d.ts`):

```ts config.yaml.d.ts icon="/icons/typescript.svg"
const contents: {
  database: {
    host: string;
    port: number;
    name: string;
  };
  server: {
    port: number;
    timeout: number;
  };
  features: {
    auth: boolean;
    rateLimit: boolean;
  };
};

export = contents;
```

***

See [YAML](/runtime/yaml).
