Skip to main content
Bun 提供了一个兼容浏览器和 Node.js 的 console 全局对象。本页仅记录 Bun 原生的 API。

对象检查深度

你可以配置 console.log() 打印嵌套对象的深度:
  • CLI 标志:使用 --console-depth <number> 为单次运行设置深度
  • 配置:在 bunfig.toml 中设置 console.depth,使其在多次运行中保持生效
  • 默认值:对象默认检查到 2 层深度
命令行参数优先于配置文件设置。

从标准输入读取

在 Bun 中,console 对象也是一个 AsyncIterable,可以逐行读取 process.stdin
adder.ts
你可以使用它来编写交互式程序,例如下面的加法计算器。
adder.ts
运行该文件:
terminal