Back to articles
Bun Shell Has a Free API You've Never Heard Of

Bun Shell Has a Free API You've Never Heard Of

via Dev.to JavaScriptAlex Spinov

Bun Shell ($) is a cross-platform shell built into Bun that lets you run shell commands directly in JavaScript/TypeScript. It's not just a child_process wrapper — it's a full shell with pipes, redirects, and globbing that works identically on macOS, Linux, and Windows. What Makes Bun Shell Special? Cross-platform — same scripts work on macOS, Linux, Windows Template literals — write shell commands as tagged templates JavaScript interop — pipe between JS and shell seamlessly Built-in — no npm install, comes with Bun The Hidden API: Shell-JavaScript Bridge import { $ } from ' bun ' ; // Run shell commands with template literals const result = await $ `echo hello world` ; console . log ( result . text ()); // 'hello world\n' // Pipe shell output to JavaScript const files = await $ `ls -la src/` . text (); const tsFiles = files . split ( ' \n ' ). filter ( f => f . endsWith ( ' .ts ' )); // Pipe JavaScript to shell const data = JSON . stringify ({ name : ' test ' , value : 42 }); await $ `

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
1 views

Related Articles