DEV Community

Alex Spinov
Alex Spinov

Posted on

Bun Shell Has a Free API You Are Not Using

Bun includes a built-in shell for running shell commands from JavaScript with template literals. Cross-platform — same syntax on macOS, Linux, and Windows.

Why Bun Shell?

Bun's shell lets you write shell scripts in JavaScript with proper error handling, type safety, and cross-platform support. No more child_process.exec.

The Free APIs You're Missing

1. Tagged Template Shell

Run any shell command with Bun's dollar-backtick syntax. Variables are safely escaped — no injection risk.

2. Output Modes

Get output as .text(), .json(), .lines(), or .blob(). Parse command output natively in JavaScript.

3. Cross-Platform

Same syntax works on macOS, Linux, and Windows. Bun translates commands to the native shell.

4. Error Handling

Use .nothrow() for graceful error handling. Access exitCode, stdout, and stderr as structured data.

5. Piping

Pipe between commands and redirect to files, just like a real shell — but with JavaScript error handling.

Getting Started

curl -fsSL https://bun.sh/install | bash
bun run script.ts
Enter fullscreen mode Exit fullscreen mode

Need data from any website delivered as clean JSON? I build production web scrapers that handle anti-bot, proxies, and rate limits. 77 scrapers running in production. Email me: Spinov001@gmail.com

Check out my awesome-web-scraping list for the best scraping tools and resources.

Top comments (0)