skills/bun-runtime-console/SKILL.md
The console object in Bun
npx skillsauth add jarle/bun-skills Bun ConsoleInstall 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.
<Note> Bun provides a browser- and Node.js-compatible [console](https://developer.mozilla.org/en-US/docs/Web/API/console) global. This page only documents Bun-native APIs. </Note>The console object in Bun
Bun allows you to configure how deeply nested objects are displayed in console.log() output:
--console-depth <number> to set the depth for a single runconsole.depth in your bunfig.toml for persistent configuration2 levelsconst nested = { a: { b: { c: { d: "deep" } } } };
console.log(nested);
// Default (depth 2): { a: { b: [Object] } }
// With depth 4: { a: { b: { c: { d: 'deep' } } } }
The CLI flag takes precedence over the configuration file setting.
In Bun, the console object can be used as an AsyncIterable to sequentially read lines from process.stdin.
for await (const line of console) {
console.log(line);
}
This is useful for implementing interactive programs, like the following addition calculator.
console.log(`Let's add some numbers!`);
console.write(`Count: 0\n> `);
let count = 0;
for await (const line of console) {
count += Number(line);
console.write(`Count: ${count}\n> `);
}
To run the file:
bun adder.ts
Let's add some numbers!
Count: 0
> 5
Count: 5
> 5
Count: 10
> 5
Count: 15
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