skills/bun-guides-process-stdin/SKILL.md
Read from stdin
npx skillsauth add jarle/bun-skills Bun Read from stdinInstall 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.
For CLI tools, it's often useful to read from stdin. In Bun, the console object is an AsyncIterable that yields lines from stdin.
const prompt = "Type something: ";
process.stdout.write(prompt);
for await (const line of console) {
console.log(`You typed: ${line}`);
process.stdout.write(prompt);
}
Running this file results in a never-ending interactive prompt that echoes whatever the user types.
bun run index.ts
Type something: hello
You typed: hello
Type something: hello again
You typed: hello again
Bun also exposes stdin as a BunFile via Bun.stdin. This is useful for incrementally reading large inputs that are piped into the bun process.
There is no guarantee that the chunks will be split line-by-line.
for await (const chunk of Bun.stdin.stream()) {
// chunk is Uint8Array
// this converts it to text (assumes ASCII encoding)
const chunkText = Buffer.from(chunk).toString();
console.log(`Chunk: ${chunkText}`);
}
This will print the input that is piped into the bun process.
echo "hello" | bun run stdin.ts
Chunk: hello
See Docs > API > Utils for more useful utilities.
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