Skip to content
Back to skills

Bun Runtime

ASecurity

Bun runtime for JavaScript/TypeScript

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added October 1, 2026
ai-agentsjavascripttypescriptgojavashellbashsqlnodeexpressapi

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned October 1, 2026

npx -y skills add ssrjkk/agent-skills --skill bun-runtime --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bun Runtime?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bun Runtime
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ssrjkk-bun-runtime-agent-skills/badge)](https://www.skillsdirectory.com/skills/ssrjkk-bun-runtime-agent-skills)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: bun-runtime
description: "Bun runtime for JavaScript/TypeScript"
category: frontend
tags: [bun, javascript, typescript, runtime, bundler]
models: [sonnet, opus]
version: 1.0.0
created: 2026-05-14
updated: 2026-09-29
---
# Bun Runtime

> Build and run JavaScript/TypeScript applications with Bun — the all-in-one toolkit.

## Quick Start
```bash
# Install Bun
powershell -c "irm bun.sh/install.ps1 | iex"

# Create a new project
bun init

# Run TypeScript directly (no ts-node needed)
bun run server.ts

# Package scripts (3-5x faster than npm)
bun install
bun add express
bun add -d typescript

# Run package.json scripts
bun run dev
bun run build

# Test runner (Jest-compatible)
bun test

# Bun's built-in bundler
bun build ./src/index.ts --outdir=./dist
```

```typescript
// bun自带 features

// Fetch API (built-in, no polyfill needed)
const response = await fetch("https://api.example.com/data");
const data = await response.json();

// SQLite (built-in)
import { Database } from "bun:sqlite";
const db = new Database(":memory:");
db.run("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");
db.run("INSERT INTO users (name) VALUES ($name)", { name: "Alice" });
const users = db.query("SELECT * FROM users").all();

// File I/O (Bun native)
const file = Bun.file("data.json");
const contents = await file.json();

// Environment variables (built-in)
const apiKey = Bun.env.API_KEY;

// WebSocket server
Bun.serve({
  port: 3000,
  fetch(req, server) {
    if (server.upgrade(req)) return; // upgrade to WebSocket
    return new Response("Hello");
  },
  websocket: {
    message(ws, message) {
      ws.send(`Echo: ${message}`);
    }
  }
});
```

## Key Concepts
Bun is a JavaScript runtime, bundler, test runner, and package manager in one. Uses JavaScriptCore (not V8), starts faster than Node.js, and is fully compatible with Node.js APIs.

## When to Use
- New TypeScript/JavaScript projects
- CI/CD pipelines needing faster installs and builds
- Development servers requiring hot reload
- Projects wanting built-in SQLite, fetch, and WebSocket support

## Step-by-Step
1. Install: run the one-line installer (`irm bun.sh/install.ps1 | iex` on Windows) and verify `bun --version`.
2. Scaffold: `bun init` creates `package.json`, `tsconfig.json`, and entry `index.ts`.
3. Write code natively: use built-in `fetch`, `Bun.file`, `bun:sqlite`, and `Bun.serve` — no polyfills, no framework.
4. Manage deps fast: `bun install`; install exact versions with `bun add <pkg>@<version>`.
5. Run and test: `bun run dev` (watch mode), `bun test` (Jest-compatible API), debug with `bun --inspect`.
6. Bundle and ship: `bun build ./src/index.ts --outdir=./dist --minify --target=bun` for a deployment artifact.

## Examples
```typescript
// REST API with built-in SQLite and typed routes
import { Database } from "bun:sqlite";

const db = new Database(":memory:");
db.run("CREATE TABLE todos (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, done INTEGER DEFAULT 0)");

Bun.serve({
  port: 3000,
  async fetch(req: Request) {
    const url = new URL(req.url);
    if (req.method === "POST" && url.pathname === "/todos") {
      const { title } = await req.json();
      const res = db.query("INSERT INTO todos (title) VALUES (?) RETURNING *").get(title);
      return Response.json(res, { status: 201 });
    }
    if (url.pathname === "/todos") {
      return Response.json(db.query("SELECT * FROM todos").all());
    }
    return Response.json({ error: "not found" }, { status: 404 });
  },
});
```
```bash
# Serve the built SPA/SSR artifact and run tests
bun run --watch src/index.ts
bun test
bun build src/index.ts --outdir=dist --minify --target=bun && bun dist/index.js
```

## Best Practices
- Use Bun for fast JS/TS runtimes, bundling, and tests.
- Prefer `bun install` for lockfile speed and compatibility.
- Use `bun test` for built-in test runner with coverage.
- Leverage `Bun.serve` for high-throughput HTTP.
- Keep dependencies minimal; Bun has many built-ins.
- Pin the Bun version in CI for reproducibility.

## Troubleshooting
- Install conflicts: clear node_modules and regenerate lockfile.
- Native bindings: match Bun version with the package.
- Runtime differences: check the Bun version in CI vs local.
- Slow cold start: use `--smol` or tweak the runtime flags.

## Validation
1. `bun --version` shows installed version
2. `bun run` executes TypeScript without compilation step
3. `bun install` is faster than npm/pnpm on the same project
4. `bun test` runs existing Jest/Vitest test suites

Files in this skill

  • SKILL.md4.4 KB
  • SKILL.ru.md5.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…