本页还没有译文
本页 10 段还没译成简体中文,下面显示的是英文原文。Console
还没翻译译自英文(bun.com)本页 10 段都还没译
Note
Bun provides a browser- and Node.js-compatible console global. This page only documents Bun-native APIs.
Object inspection depth
You can configure how deeply console.log() prints nested objects:
- CLI flag: Use
--console-depth <number>to set the depth for a single run - Configuration: Set
console.depthin yourbunfig.tomlto persist it across runs - Default: Bun inspects objects to a depth of
2levels
const nested = { a: { b: { c: { d: "deep" } } } };
console.log(nested);
// Default (depth 2): { a: { b: { c: [Object ...] } } }
// With depth 4: { a: { b: { c: { d: 'deep' } } } }The CLI flag takes precedence over the configuration file setting.
Reading from stdin
In Bun, the console object is also an AsyncIterable that reads process.stdin line by line.
for await (const line of console) {
console.log(line);
}Use this for 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: 15AI 翻译查看英文原文