Skip to content
Run BunYour friendly Bun playground

Console

The console is a terminal under the editor. It runs bun and git commands, a shell over the project’s files, and shows your program’s output.

A terminal with colors, clickable links, history (↑/↓) and line editing (Ctrl+A/E/U). Ctrl+C on an empty line stops the server; Ctrl+L clears.

Command Does
bun run <script|file>, bun <file> Run a package.json script or a file; --preload <file> (-r, --require, --import) runs a module first, after bunfig.toml’s preload, as in Bun
bun test [-u] [--coverage] [-t pattern] [filter…] Run *.test.* / *.spec.* files with bun:test; --coverage reports which lines and functions ran, -t runs the tests whose name matches (also --timeout, --bail, --rerun-each, --todo, --only)
bun install (i) Install dependencies
bun add <pkg[@range]> [-d] (a) Add a dependency
bun remove <pkg> (rm) Remove a dependency
bun pm cache [rm] Show or clear the package cache
bun fmt [-c] [path…] Format files like Prettier, or only check them (-c)
bun check [path…] Type check with Bun’s own checker, as bun check does
git <command> Version control for the project: init, status, add, commit, log, diff, show, branch, switch, restore, reset, config… (see Git)
echo, cd, pwd, ls, cat, touch, mkdir, rm, mv, cp, which, export, seq, yes, dirname, basename, true, false, exit Bun’s shell builtins, over the project’s files
cookies [clear] List or clear the preview’s cookies
reset Throw away your changes and reload the project from its source
clear, help

The console is Bun’s shell, the one Bun.$ runs: quotes, pipes (ls | cat), &&, || and ;, redirects (echo hi > notes.txt, 2>&1), variables (x=1, export, $x), $(…), globs (ls src/*.ts), {a,b} and subshells.

How cd, the console's own commands and bun run scripts behave
  • cd changes the folder the next commands run in (the prompt shows it; / is the project).
  • The console’s own commands (bun, git, cookies…) take part too, though only their messages follow a pipe, not a running program’s output.
  • Commands outside this list aren’t found, so no bunx, grep or node here.
  • bun run of a package.json script that is more than a file or a bin (tsc && vite build) runs the script line in Bun’s shell as the program, each of its commands a child process, as a running program’s Bun.spawn and child_process start them.

A program that reads its input (process.stdin, Bun.stdin, for await (const line of console), readline, prompt()) gets what you type in the console. While it waits, Enter sends the line to the program instead of running it as a command, and the line stays in the output as in a terminal, after the program’s prompt (Name? Bob).

Ending input, raw mode, and what doesn't get input yet

Line input

  • Ctrl+D on an empty line ends the input; after text it sends the text without a newline first.
  • Ctrl+C stops the program.
  • Pasted text goes line by line.
  • When the program isn’t reading, the console is the shell again, also while a server runs.
  • In an embed it is the same console.
  • Output that ends without a newline (process.stdout.write("Name? ")) stays on its row for what comes next.

Raw mode

A program that calls process.stdin.setRawMode(true) (a prompt library such as @clack/prompts, readline in terminal mode, a TUI) gets every key at once as the bytes a terminal sends (Enter \r, Backspace \x7f, arrows, Tab, Esc, Home, End, Delete), without echo. Ctrl+C and Ctrl+D go to the program too, so the program decides whether to stop. The console draws what such a program writes, cursor movement and line clearing included. When the program leaves raw mode the console is line by line again.

Limits

  • A program that runs with Local Bun doesn’t get input yet.
  • prompt(), confirm() and alert() need a cross-origin isolated page (see Bun APIs).

Was this page helpful?

Sends the rating and this page's address; nothing else unless you write it. Privacy

runbun is an independent project, not affiliated with or endorsed by Oven or Bun.