rembrembdocs

Skip to main content

Bun home pagelight logodark logo

[Runtime

](../../index.md)[Package Manager

](../../pm/cli/install/index.md)[Bundler

](../../bundler/index.md)[Test Runner

](../../test/index.md)[Guides

](../../guides/index.md)[Reference

](https://bun.com/reference)[Blog

](https://bun.com/blog)[Feedback

](../../feedback/index.md)

Bun provides a browser- and Node.js-compatible console global. This page only documents Bun-native APIs.


[​

](#object-inspection-depth)

Object inspection depth

Bun allows you to configure how deeply nested objects are displayed in console.log() output:

const 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.


[​

](#reading-from-stdin)

Reading from stdin

In Bun, the console object can be used as an AsyncIterable to sequentially read lines from process.stdin.

https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35badder.ts

for await (const line of console) {
  console.log(line);
}

This is useful for implementing interactive programs, like the following addition calculator.

https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35badder.ts

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:

terminal

bun adder.ts
Let's add some numbers!
Count: 0
> 5
Count: 5
> 5
Count: 10
> 5
Count: 15

Was this page helpful?

Suggest editsRaise issue

[

Secrets

Previous

](../secrets/index.md)[

TOML

Next

](../toml/index.md)