skills/bun-guides-runtime-import-yaml/SKILL.md
Import a YAML file
npx skillsauth add jarle/bun-skills Bun Import a YAML fileInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Bun natively supports .yaml and .yml imports.
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.
import config from "./config.yaml";
config.database.host; // => "localhost"
config.server.port; // => 3000
config.features.auth; // => true
You can also use named imports to destructure top-level properties:
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 syntax:
import config from "./config.yaml" with { type: "yaml" };
config.database.port; // => 5432
For parsing YAML strings at runtime, use Bun.YAML.parse():
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"]
To add TypeScript support for your YAML imports, create a declaration file with .d.ts appended to the YAML filename (e.g., config.yaml → config.yaml.d.ts);
const contents: {
database: {
host: string;
port: number;
name: string;
};
server: {
port: number;
timeout: number;
};
features: {
auth: boolean;
rateLimit: boolean;
};
};
export = contents;
See Docs > API > YAML for complete documentation on YAML support in Bun.
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling