Логотип Bun

Bun

Спільнота
j4flmao
bun

Use this skill when the user says 'bun', 'bun runtime', 'bun install', 'bun test', 'bun build', 'Bun.serve', 'bun:sqlite', 'Bun.file', 'Bun shell', 'bun --compile'. Builds TypeScript/JavaScript backends and tools on the Bun runtime: Bun.serve HTTP/WebSocket servers, bun:sqlite, file I/O, Bun Shell scripts, the built-in test runner, bundler and single-file executables. Do NOT use for: Elysia-specific architecture (elysia-architecture), Hono apps (nodejs-hono), Deno (deno), Node.js-only deployments (nodejs-architecture), browser JavaScript.

Огляд

Видавецьj4flmao
Репозиторійagent-skills
Назва навичкиbun
Зірки
41
Форки
6
Файли в пакеті
6
ЛіцензіяMIT
Посилання
  • Інструкції у форматі Markdown

    Файл SKILL.md, який модель завантажує за потреби, тож токени витрачаються лише тоді, коли запит справді відповідає навичці.

  • Працює з будь-якою LLM

    Навички ШІ — це звичайний Markdown, а не код для певного постачальника, тому вони працюють із GPT, Claude, Gemini, Grok або локальною моделлю.

  • Файлів у комплекті: 6

    Скрипти, шаблони й довідкові матеріали, які модель може читати під час роботи. Файли доступні лише для читання й ніколи не виконуються.

  • Відкритий вихідний код

    Опубліковано на GitHub користувачем j4flmao. Перегляньте вихідний вміст перед установленням.

Встановлення

Установіть навичку ШІ Bun у TypingMind, щоб використовувати її з будь-якою LLM, або додайте її до іншого агента, що читає SKILL.md.

1

Встановити в TypingMind

TypingMind встановлює навичку безпосередньо з її папки GitHub — читає SKILL.md, збирає файли ресурсів у пакет і зберігає результат локально.

  1. Відкрийте застосунок і перейдіть до Плагіни → Навички.
  2. Виберіть «Встановити з GitHub».
  3. Вставте наведений нижче URL папки навички та підтвердьте встановлення.
    https://github.com/j4flmao/agent-skills/tree/main/skills/backend/bun
  4. Увімкніть навичку в кожному чаті, де хочете її використовувати.
Плагіни → Навички → Нова навичка → За URL GitHub, потім вставте URL папки й натисніть «Продовжити».
2

Встановити в іншому агенті

Будь-який агент, що підтримує формат Agent Skills, може використовувати цю навичку — скопіюйте папку до каталогу навичок цього агента.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/j4flmao/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/backend/bun .claude/skills/bun
Після копіювання перезапустіть Claude Code, щоб завантажити нову навичку.

Використовуйте навичку в TypingMind

Увімкніть навичку Bun в будь-якому чаті TypingMind, і далі модель усе зробить сама. Назва й опис навички містяться в системному промпті, а щойно надходить відповідний запит, модель самостійно завантажує повні інструкції — вам не потрібно викликати навичку вручну, і до фактичного використання вона не витрачає токенів.

Модель самостійно завантажує навичку Bun, щойно надходить відповідний запит.

Працює з будь-якою моделлю ШІ

Навички ШІ — це звичайні інструкції Markdown, а не код для певного постачальника, тому навичка Bun не прив’язана до моделі, для якої її створено. Установіть її один раз у TypingMind і використовуйте з GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama або локальною моделлю, яку ви запускаєте самостійно, — усе з вашими власними ключами API.

  • Завантажується лише за потреби

    Системний промпт містить лише назву й опис. Інструкції завантажуються за першого відповідного запиту, тож невикористана навичка нічого не коштує.

  • Змінюйте моделі під час чату

    Оскільки навичка — це інструкції, а не код, зміна моделі не порушує її роботу: наступна модель читає той самий файл SKILL.md.

Інструкції навички

Це вміст файлу SKILL.md, який завантажує модель. Прочитайте його перед установленням — навичка містить інструкції, яких дотримуватиметься ваша модель.

Bun

Purpose

Build TypeScript/JavaScript services and tooling on Bun, using its built-in server, SQLite driver, file APIs, shell, test runner and bundler where they simplify the stack, while staying aware of where Node.js compatibility still matters.

Agent Protocol

Trigger

Exact user phrases: "bun", "bun runtime", "bun install", "bun test", "bun build", "Bun.serve", "bun:sqlite", "Bun.file", "Bun shell", "bun --compile".

Input Context

  • Target: API server, CLI tool, scripts, or library.
  • Framework on top of Bun (none, Elysia, Hono, Express via Node compatibility).
  • Database (bun:sqlite, PostgreSQL via Bun.sql or postgres/pg, Redis).
  • Deployment target (Docker, single binary, serverless).

Output Artifact

Project layout, server/test/build code and package.json scripts. No files unless requested.

Response Format

Runtime: Bun {version}   Framework: {none|Elysia|Hono|Express}
Server: Bun.serve {routes|fetch}   DB: {bun:sqlite|Bun.sql|other}
Scripts: dev/test/build/compile
Code: {files}
Node-compat risks: {native addons, unsupported node: APIs}

Runtime Choice

CriterionBunNode.jsDeno
TypeScriptRuns .ts directly (transpile only, no type-check)Type stripping built in since Node 22.18/23.6 for erasable syntax; otherwise tsx/build stepRuns .ts directly; deno check type-checks
npm packagesHigh compatibility; native addons and some node: APIs can still differReference implementationnpm via npm: specifiers
Built-insHTTP server, WebSocket, SQLite, Postgres client, S3 client, password hashing, shell, test runner, bundlerTest runner, node:sqlite (newer versions)HTTP, KV, test runner, formatter, linter
MaturityYoungest; verify critical dependenciesMost mature, widest hosting supportMature, strong permissions model

Decision: choose Bun when its built-ins remove dependencies and your dependency set is verified to work; keep Node.js when you rely on native addons, APM agents or hosting that only supports Node. Always type-check separately (tsc --noEmit) because Bun does not.

Startup-time and requests-per-second comparisons vary by benchmark and version; measure on your own workload rather than quoting published numbers.

Workflow

Step 1: Project Initialization

bash
bun init -y                 # package.json, tsconfig.json, index.ts
bun add zod                 # dependencies (writes text lockfile bun.lock)
bun add -d @types/bun typescript
my-app/
  src/
    index.ts          # Bun.serve entry
    routes/users.ts
    db/sqlite.ts
  tests/users.test.ts
  bun.lock
  package.json
  tsconfig.json

Step 2: HTTP Server with Bun.serve

Bun 1.2.3+ supports a routes table with path parameters; fetch handles everything else.

ts
// src/index.ts
import { createUser, findUserById, findAllUsers } from './db/sqlite';

const server = Bun.serve({
  port: Number(process.env.PORT ?? 3000),
  routes: {
    '/health': () => Response.json({ status: 'ok' }),
    '/api/v1/users': {
      GET: () => Response.json({ data: findAllUsers() }),
      POST: async (req) => {
        const body = (await req.json()) as { name?: string; email?: string };
        if (!body.name || !body.email) {
          return Response.json({ error: 'name and email required' }, { status: 400 });
        }
        return Response.json({ data: createUser(body.name, body.email) }, { status: 201 });
      },
    },
    '/api/v1/users/:id': (req) => {
      const user = findUserById(req.params.id);
      return user ? Response.json({ data: user }) : Response.json({ error: 'not found' }, { status: 404 });
    },
  },
  fetch() {
    return Response.json({ error: 'not found' }, { status: 404 });
  },
  error(err) {
    console.error('unhandled request error', err);
    return Response.json({ error: 'internal error' }, { status: 500 });
  },
});

console.log(`listening on ${server.url}`);

Step 3: bun:sqlite

ts
// src/db/sqlite.ts
import { Database } from 'bun:sqlite';

export interface User { id: string; name: string; email: string; created_at: string }

const db = new Database(process.env.DB_PATH ?? './data/app.db', { create: true, strict: true });
db.exec('PRAGMA journal_mode = WAL;');
db.exec('PRAGMA foreign_keys = ON;');
db.exec(`
  CREATE TABLE IF NOT EXISTS users (
    id TEXT PRIMARY KEY,
    name TEXT NOT NULL,
    email TEXT UNIQUE NOT NULL,
    created_at TEXT NOT NULL DEFAULT (datetime('now'))
  )`);

// strict: true lets you bind { id } instead of { $id }
const insertUser = db.query('INSERT INTO users (id, name, email) VALUES ($id, $name, $email)');
const getUser = db.query<User, { id: string }>('SELECT * FROM users WHERE id = $id');
const listUsers = db.query<User, { limit: number; offset: number }>(
  'SELECT * FROM users ORDER BY created_at DESC LIMIT $limit OFFSET $offset',
);

export function createUser(name: string, email: string): User {
  const id = crypto.randomUUID();
  insertUser.run({ id, name, email });
  return getUser.get({ id })!;
}

export function findUserById(id: string): User | null {
  return getUser.get({ id });
}

export function findAllUsers(limit = 20, offset = 0): User[] {
  return listUsers.all({ limit, offset });
}

db.query() caches the prepared statement; db.prepare() does not. SQLite allows one writer at a time even in WAL mode; it suits single-node services, not multi-instance deployments.

Step 4: File I/O

ts
import { join, basename } from 'node:path';
import { unlink } from 'node:fs/promises';

const UPLOAD_DIR = './uploads';
const safePath = (name: string) => join(UPLOAD_DIR, basename(name)); // block ../ traversal

export async function saveFile(name: string, data: Blob | ArrayBuffer | Uint8Array | string) {
  await Bun.write(safePath(name), data);
}

export async function serveFile(name: string): Promise<Response> {
  const file = Bun.file(safePath(name));
  if (!(await file.exists())) return new Response('not found', { status: 404 });
  return new Response(file); // streams, sets Content-Type from extension
}

export async function deleteFile(name: string) {
  await unlink(safePath(name));
}

Bun.file() paths resolve against the current working directory; use import.meta.dir for script-relative paths.

Step 5: Tests with bun:test

ts
// tests/users.test.ts
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
import type { Server } from 'bun';

let server: Server;
let base: string;

beforeAll(async () => {
  process.env.DB_PATH = ':memory:';
  process.env.PORT = '0';                     // random free port
  server = (await import('../src/index')).default; // index.ts: export default server
  base = `http://localhost:${server.port}/api/v1`;
});

afterAll(() => server.stop(true));

describe('users API', () => {
  it('creates then fetches a user', async () => {
    const created = await fetch(`${base}/users`, {
      method: 'POST',
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify({ name: 'Alice', email: 'alice@example.com' }),
    });
    expect(created.status).toBe(201);
    const { data } = await created.json();
    const fetched = await fetch(`${base}/users/${data.id}`);
    expect(fetched.status).toBe(200);
  });

  it('returns 404 for unknown user', async () => {
    const res = await fetch(`${base}/users/does-not-exist`);
    expect(res.status).toBe(404);
  });
});

For this to work, export the server from src/index.ts (export default server;). Use mock(), spyOn() and mock.module() from bun:test for doubles; bun test --coverage for coverage.

Step 6: Scripts, Build and Single Binary

json
{
  "scripts": {
    "dev": "bun --watch src/index.ts",
    "start": "bun src/index.ts",
    "test": "bun test",
    "typecheck": "tsc --noEmit",
    "build": "bun build src/index.ts --outdir dist --target bun --minify",
    "compile": "bun build src/index.ts --compile --outfile dist/app"
  }
}

--compile embeds the Bun runtime into a standalone executable; cross-compile with --target=bun-linux-x64 etc.

Implementation Patterns

WebSocket Broadcast with Built-in Pub/Sub

ts
type WsData = { room: string };

const server = Bun.serve({
  port: 3000,
  fetch(req, server) {
    const room = new URL(req.url).searchParams.get('room') ?? 'lobby';
    if (server.upgrade(req, { data: { room } })) return;
    return new Response('Expected WebSocket', { status: 426 });
  },
  websocket: {
    open(ws) { ws.subscribe((ws.data as WsData).room); },
    message(ws, message) {
      // publish to every subscriber except the sender
      ws.publish((ws.data as WsData).room, message);
    },
    close(ws) { ws.unsubscribe((ws.data as WsData).room); },
  },
});

Pub/sub is per process; use Redis or NATS to fan out across instances.

Bun Shell Scripts

ts
import { $ } from 'bun';

$.throws(true); // non-zero exit codes throw ShellError
const branch = (await $`git rev-parse --abbrev-ref HEAD`.text()).trim();
await $`bun test`;
await $`docker build -t my-app:${branch} .`;

Interpolated values are escaped, so ${userInput} cannot inject shell syntax. Bun Shell is cross-platform for its built-in commands (ls, cd, rm, echo, ...); external programs must exist on the host.

Password Hashing

ts
// Default algorithm is argon2id; bcrypt is also supported.
const hash = await Bun.password.hash(plain);                 // argon2id
const ok = await Bun.password.verify(plain, hash);           // detects algorithm from hash
const legacy = await Bun.password.hash(plain, { algorithm: 'bcrypt', cost: 12 });

Production Considerations

  • Docker: use the official oven/bun image pinned to a version (not latest), multi-stage build, bun install --frozen-lockfile --production.
  • Multiple cores: run several processes with Bun.serve({ reusePort: true }) (Linux load-balances them) or use node:cluster; one Bun process uses one JS thread.
  • Memory-constrained environments: run with bun --smol to trade throughput for lower memory.
  • Outbound calls: set timeouts explicitly with AbortSignal.timeout(ms) on fetch.
  • Graceful shutdown: handle SIGTERM and call server.stop() to finish in-flight requests.
  • Observability: confirm your APM/OpenTelemetry instrumentation supports Bun before committing; many auto-instrumentations target Node.js.

Security Considerations

  • Sanitize file names before using them in paths (see basename above).
  • Add security headers yourself (no helmet equivalent built into Bun.serve), or use a framework middleware.
  • Validate request bodies with a schema library (zod, valibot, TypeBox); req.json() returns untyped data.
  • Pin the Bun version in CI and Docker; review lifecycle scripts, which Bun only runs for packages listed in trustedDependencies.

Anti-Patterns

Anti-patternFix
Relying on Bun to catch type errorsRun tsc --noEmit in CI
file.exists() without awaitIt returns a Promise; always await
Assuming every Node native addon worksTest critical deps; keep a Node fallback path if needed
Using bun:sqlite for multi-instance shared statePostgreSQL/MySQL
Unpinned oven/bun:latest imagesPin the version
One process on a multi-core box expecting full CPU usereusePort workers or cluster

Checklist

  • Bun version pinned (packageManager/.bun-version, Docker tag, CI).
  • Type-check step in CI alongside bun test.
  • Dependencies verified on Bun (especially native addons, APM agents).
  • Timeouts on outbound fetches; graceful shutdown on SIGTERM.
  • Input validation and safe path handling.

Handoff

Elysia apps: skills/backend/elysia/architecture/SKILL.md. Hono apps: skills/backend/nodejs/hono/SKILL.md.

References

Файли в пакеті

Модель читає ці файли за потреби, поки навичку завантажено. Вони доступні для читання й ніколи не виконуються.

Поширені запитання

Що робить навичка ШІ Bun?

Use this skill when the user says 'bun', 'bun runtime', 'bun install', 'bun test', 'bun build', 'Bun.serve', 'bun:sqlite', 'Bun.file', 'Bun shell', 'bun --compile'. Builds TypeScript/JavaScript backends and tools on the Bun runtime: Bun.serve HTTP/WebSocket servers, bun:sqlite, file I/O, Bun Shell scripts, the built-in test runner, bundler and single-file executables. Do NOT use for: Elysia-specific architecture (elysia-architecture), Hono apps (nodejs-hono), Deno (deno), Node.js-only deployments (nodejs-architecture), browser JavaScript.

Навіщо використовувати Bun у TypingMind?

Тому що ви встановлюєте її один раз і використовуєте з будь-якою моделлю. Bun — це звичайний Markdown, а не код для конкретного постачальника, тому та сама навичка працює з GPT-5, Claude, Gemini, Grok або локальною моделлю. Ви можете змінити модель навіть посеред чату, і навичка продовжить працювати. TypingMind використовує ваші власні ключі API, тож ви платите безпосередньо постачальникам замість передплати за кожне місце користувача, а ваші навички й чати залишаються у вашому сховищі.

Як встановити Bun у TypingMind?

Відкрийте в TypingMind Плагіни → Навички → Встановити з GitHub і вставте https://github.com/j4flmao/agent-skills/tree/main/skills/backend/bun. TypingMind прочитає файл SKILL.md, додасть супровідні файли та встановить навичку, яку можна вмикати окремо для кожного чату.

Які моделі ШІ можуть використовувати Bun?

Будь-яка модель, яку ви підключите в TypingMind. Навички ШІ — це звичайні інструкції у форматі Markdown, а не код для конкретного постачальника, тому GPT, Claude, Gemini, Grok і локальні моделі можуть завантажувати цю навичку, коли запит їй відповідає.

Зі скількома моделями ШІ можна використовувати Bun?

Зі скількома забажаєте. Якщо модель підтримує навички, ви можете використовувати з нею Bun — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama та інші — усе в TypingMind із власними ключами API.

Чи безкоштовна навичка ШІ Bun?

Так. Навичку опубліковано на GitHub: j4flmao, за ліцензією MIT. Ви платите лише своєму постачальнику ШІ за використані токени.

Що таке навички ШІ?

Навичка ШІ — це багаторазовий набір інструкцій, який навчає модель ШІ виконувати одне конкретне завдання. Він відповідає відкритому формату Agent Skills: файл SKILL.md із назвою та описом, а також скрипти, шаблони чи довідкові файли, які можуть знадобитися моделі. Модель читає інструкції лише тоді, коли ваш запит відповідає навичці, тому встановлена навичка нічого не коштує, доки її не використано.

Чим навички ШІ відрізняються від плагінів або серверів MCP?

Плагін або сервер MCP надає моделі нові інструменти для виклику — код, який десь виконується й повертає результат. Натомість навичка ШІ надає моделі знання та порядок дій: як підійти до завдання, яких кроків дотримуватися та яким має бути якісний результат. Навички — це звичайний Markdown, тож їм не потрібні ні сервер, ні ключ API, ні середовище виконання, і вони працюють із будь-якою моделлю.

Усі

Створіть власний ШІ-простір уже зараз

Підпишіться на нашу розсилку, щоб дізнаватися про нові функції та майбутні розіграші 👇