bun run tsc --noEmit`.text();\n console.log('TypeScript:', tscResult);\n\n // Build bundle\n await
bun · Skills-SI マーケット
bun build src/index.ts --outdir dist --target bun --minify`;\n\n // Run tests\n const testResult = await
bun · Skills-SI マーケット
bun test`.text();\n console.log('Tests:', testResult);\n\n // Build Docker image\n await
bun · Skills-SI マーケット
docker build -t my-app:latest .`;\n\n // Deploy\n await
bun · Skills-SI マーケット
docker push my-app:latest`;\n\n // Chained commands\n const [gitBranch, gitHash] = await Promise.all([\n
bun · Skills-SI マーケット
git rev-parse --abbrev-ref HEAD`.text(),\n
bun · Skills-SI マーケット
git rev-parse --short HEAD`.text(),\n ]);\n\n console.log(`Deployed ${gitBranch.trim()}@${gitHash.trim()}`);\n}\n\n// Piped commands\nconst fileCount = await
bun · Skills-SI マーケット
ls src/**/*.ts | wc -l`.text();\nconsole.log(`Source files: ${fileCount.trim()}`);\n```\n\n### Pattern: Bun Password Hashing\n\n```typescript\nimport { password } from 'bun';\n\nexport class AuthService {\n async hashPassword(plain: string): Promise\u003cstring> {\n return await password.hash(plain, {\n algorithm: 'bcrypt',\n cost: 10,\n });\n }\n\n async verifyPassword(plain: string, hash: string): Promise\u003cboolean> {\n return await password.verify(plain, hash);\n }\n\n async hashArgon2(plain: string): Promise\u003cstring> {\n return await password.hash(plain, {\n algorithm: 'argon2id',\n timeCost: 3,\n memoryCost: 65536,\n parallelism: 1,\n });\n }\n}\n```\n\n### Pattern: Binary Compilation\n\n```typescript\n// bun build --compile --outfile my-server src/index.ts\n// Produces standalone binary (no Bun runtime needed)\n\nimport { Command } from 'commander';\nconst program = new Command();\nprogram\n .name('my-cli')\n .version(Bun.version)\n .command('serve')\n .option('-p, --port \u003cnumber>', 'Port', '3000')\n .action((opts) => {\n Bun.serve({\n port: parseInt(opts.port),\n fetch: () => new Response('Compiled Bun server'),\n });\n });\n\nprogram.parse();\n\n// Build: bun build src/cli.ts --compile --outfile dist/app\n// Run: ./dist/app serve --port 8080\n```\n\n## Production Considerations\n\n### Performance\n- Use `Bun.serve` with `--smol` flag for memory-constrained environments\n- Bun.sqlite with WAL mode + `synchronous = NORMAL` for write-heavy workloads\n- Monitor: use `process.memoryUsage()` and `process.cpuUsage()` for metrics\n- Memory: Bun uses jemalloc; set `MALLOC_CONF` env var for tuning (e.g., `MALLOC_CONF=background_thread:true`)\n- Cluster: use `Bun.spawn` to fork workers; built-in cluster module not yet available\n\n### Deployment\n- Docker: `oven/bun:latest` base image; multi-stage build for production\n- Binary compilation: use `--compile` flag to produce standalone binary (no runtime deps)\n- CI: use `bun install --frozen-lockfile` for reproducible installs\n- Environment variables: validated at startup with `.env` + Zod schema\n\n### Common Issues\n- `Bun.file()` paths are relative to working directory, not script location\n- Bun's `fetch` has different timeout defaults than Node.js — set `signal: AbortSignal.timeout(5000)`\n- Hot reload (`--watch`) watches files but not node_modules — restart for dep changes\n- Bun's `crypto.randomUUID()` and Node.js `crypto.randomUUID()` are compatible\n\n## Anti-Patterns\n\n| Anti-Pattern | Why | Fix |\n|-------------|-----|-----|\n| Using `process.nextTick` | Bun supports it but prefers microtask queue | Use `queueMicrotask` or `Promise.resolve().then()` |\n| Importing `fs`/`path` when Bun APIs exist | Bun.file/Bun.write are faster and simpler | Use `Bun.file()`, `Bun.write()`, `Bun.spawn()` |\n| Using Jest/Vitest | Bun test is built-in and faster (uses same API) | `import { describe, it, expect } from 'bun:test'` |\n| npm install instead of bun install | Slower by 10-30x | Always `bun install` |\n| ts-node or tsx for running TypeScript | Bun runs TS natively | `bun src/index.ts` directly |\n| Using Bull/BullMQ with Bun | Bun has its own queue pattern with `Bun.sleep` | Use Redis + Bun.serve or Elysia instead |\n| Nested node_modules | Bun uses flat structure via bun.lock | Always `bun install` — avoids Windows path length issues |\n\n## Security Considerations\n- Bun's built-in `password.hash` uses bcrypt by default (not pbkdf2 like Node.js) — set cost >= 10\n- Bun stores .bun install cache at `~/.bun/install/cache/` — clear in CI environments\n- Use `--smol` option in Docker to limit memory; set `BUN_RUNTIME_TRANSPILER_CACHE_PATH` to /tmp\n- Bun's `fetch` supports `credentials: 'omit'` by default (safer than Node.js undici defaults)\n- Validate `req.param()` in Bun.serve — Bun returns string not string | undefined like Express\n- Bun has no built-in `helmet` equivalent — add security headers manually in `fetch` handler\n- Use `bun update --latest` instead of individual npm updates — checks integrity via lockfile\n\n## Testing Strategies\n\n```typescript\nimport { describe, expect, it, mock, spyOn, beforeAll, afterAll } from 'bun:test';\n\n// Mock global\nconst mockFetch = mock(() => new Response(JSON.stringify({ ok: true })));\nglobalThis.fetch = mockFetch;\n\n// Spy on module functions\nconst logger = { info: () => {}, error: () => {} };\nconst spy = spyOn(logger, 'info');\n\ndescribe('Bun-specific tests', () => {\n it('reads file with Bun.file', async () => {\n await Bun.write('/tmp/test.txt', 'hello world');\n const file = Bun.file('/tmp/test.txt');\n expect(await file.text()).toBe('hello world');\n expect(file.size).toBe(11);\n });\n\n it('runs shell command', async () => {\n const result = await Bun.
bun · Skills-SI マーケット
echo \"hello\"`.text();\n expect(result.trim()).toBe('hello');\n });\n\n it('hashes password', async () => {\n const hash = await Bun.password.hash('secret', { algorithm: 'bcrypt', cost: 4 });\n expect(await Bun.password.verify('secret', hash)).toBe(true);\n expect(await Bun.password.verify('wrong', hash)).toBe(false);\n });\n\n it('benchmarks performance', () => {\n const start = performance.now();\n for (let i = 0; i \u003c 10000; i++) crypto.randomUUID();\n const end = performance.now();\n expect(end - start).toBeLessThan(500);\n });\n\n it('handles SQLite transactions', () => {\n const db = new Database(':memory:');\n db.run('CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)');\n const insert = db.prepare('INSERT INTO test (value) VALUES (?)');\n const select = db.prepare('SELECT * FROM test');\n\n const tx = db.transaction(() => {\n insert.run('a');\n insert.run('b');\n });\n tx();\n\n expect(select.all().length).toBe(2);\n });\n});\n```\n\n- Use `bun test --coverage` for coverage reports (built-in, no nyc/istanbul needed)\n- Use `bun test --watch` for TDD\n- For integration tests: spin up Bun.serve in beforeAll, shut down in afterAll\n- Test binary compilation with `bun build --compile` in CI pipeline\n- Benchmark performance with `Bun.nanoseconds()` for precise timing\n\n## Rules\n - references/bun-advanced.md — Bun Advanced Topics\n - references/bun-deployment.md — Bun Deployment\n - references/bun-ecosystem.md — Bun Ecosystem\n - references/bun-essentials.md — Bun Essentials\n - references/bun-fundamentals.md — Bun Fundamentals\n - references/bun-tooling.md — Bun Tooling\n## Handoff\nHand off to `backend/elysia/SKILL.md` for Elysia framework or `backend/universal/testing/SKILL.md` for testing patterns.\n","licenseDocuments":[]}}
Use this skill when building with Bun runtime — Bun APIs, testing, package management, shell scripting, hot reload, SQLite, file I/O. This skill enforces: built-in APIs over npm equivalents, Bun test runner, bun install speed optimization, Bun.shell for scripts. Do NOT use for: Node.js-specific APIs (process.nextTick), Deno-specific features, browser JavaSc…
Independent GitHub snapshot · Automated classification · Original documentation governs
name: bun
description: >
Use this skill when building with Bun runtime — Bun APIs, testing, package management, shell scripting, hot reload, SQLite, file I/O. This skill enforces: built-in APIs over npm equivalents, Bun test runner, bun install speed optimization, Bun.shell for scripts. Do NOT use for: Node.js-specific APIs (process.nextTick), Deno-specific features, browser JavaScript.
version: "1.0.0"
author: "j4flmao"
license: "MIT"
compatibility:
claude-code: true
cursor: true
codex: true
windsurf: true
tags: [backend, bun, phase-10]
Bun
Purpose
Build high-performance TypeScript/JavaScript applications with Bun runtime — built-in APIs, test runner, package manager, bundler, and shell scripting.
Architecture Decision Trees
Runtime Selection: Bun vs Node.js vs Deno
Criterion
Bun
Node.js
Deno
Startup time
~5ms
~50ms
~20ms
npm compatibility
~95%
100%
~80%
TypeScript native
Yes (transpiled)
No (ts-node/esbuild)
Yes (compiled)
Built-in APIs
SQLite, fetch, WebSocket, password hashing
None (npm)
Web APIs, KV, FFI
Test runner
Built-in (Jest-compatible)
Mocha/Jest/Vitest
Built-in
Bundler
Built-in (esbuild-level)
esbuild/webpack/rollup
Built-in
Package manager
Built-in (10x faster)
npm/pnpm/yarn
Custom
Shell scripting
Bun.shell (built-in)
execa/child_process
Deno.Command
Windows support
Experimental (native)
Mature
Mature
Docker image size
~200MB
~350MB
~200MB
Decision: Bun for new projects prioritizing DX and speed. Node.js for max ecosystem compatibility. Deno for security-first or edge computing.
Server Framework Decision
Criterion
Bun.serve (raw)
Elysia
Hono
Express (compat)
Performance
~100k req/s
~80k req/s
~90k req/s
~30k req/s
Bundle size
0
Tiny
Tiny
Medium
TypeScript
Manual
Full (Eden)
Full (TypeBox)
Partial
Plugins
None
Rich
Growing
Largest
Learning curve
Low
Medium
Low
Low
Best for
APIs, microservices
Full-stack TypeScript
Edge, Workers, API
Migration from Node
Decision: Elysia for new full-stack TypeScript apps. Bun.serve for minimal APIs. Hono for edge/Cloudflare Workers.
Bun.sqlite vs External DB
Criterion
Bun.sqlite
PostgreSQL
MySQL
Latency
<1ms (in-process)
1-5ms (network)
1-5ms (network)
Concurrent writes
WAL mode (good)
Excellent
Excellent
Data size
<100GB practical
Unlimited
Unlimited
Replication
None
Streaming + cascading
Group replication
Full-text search
FTS5 built-in
tsvector
Fulltext index
Backup
.backup command
pg_dump/WAL archiving
mysqldump
Decision: Bun.sqlite for single-server, embedded, or dev. PostgreSQL for production multi-server.
Agent Protocol
Trigger
User request includes: Bun, bun runtime, bun.sh, bun run, bun test, bun install, bun build, bunx, hot reload, bun --watch, Bun.file, Bun.write, Bun.serve, Bun.sqlite, Bun.shell.
Input Context
Runtime (Bun, Bun in Docker)
Framework (Elysia, Hono, Express compatibility)
Database (Bun SQLite, PostgreSQL, MySQL)
Build target (API, CLI tool, script)
Output Artifact
Project setup with Bun APIs, test configuration, build scripts, runtime config.
Response Format
Produce artifact directly. No preamble, no postamble, no explanations. No filler, no hedging, no transitions. Strip articles a/an/the where unambiguous. Compress output — why use many token when few do trick.
Completion Criteria
Bun APIs used over Node.js equivalents where applicable
Test suite configured with Bun test
Package scripts optimized for Bun
Build config with bun build
Max Response Length
4096 tokens
Workflow
Step 1: Project Initialization
bun init # Create new project (package.json + tsconfig.json)
bun init -y # Skip prompts
bun create elysia my-app # Elysia starter
bun create hono my-app # Hono starter
bun create next my-app # Next.js on Bun