bun-patterns

Grips001's avatarfrom Grips001

Verify Bun-specific patterns in backend code. Use when reviewing or writing backend TypeScript files to ensure Bun APIs are used instead of Node.js patterns.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 8, 2026⬇️3downloads

When & Why to Use This Skill

The Bun Patterns Verification skill automates the auditing of backend TypeScript code to ensure full compatibility and performance optimization with the Bun runtime. By identifying and replacing legacy Node.js patterns with native Bun APIs for file I/O, environment management, and HTTP services, it helps developers maintain a modern, high-performance codebase while reducing technical debt.

Use Cases

  • Node.js to Bun Migration: Automatically scan legacy codebases to identify Node.js 'fs' imports and 'process.env' calls that need to be refactored for Bun compatibility.
  • Automated Pull Request Audits: Integrate into the code review workflow to ensure new backend contributions follow project-specific Bun standards and utilize optimized native APIs.
  • File System Optimization: Refactor asynchronous file operations by replacing 'fs/promises' with the more efficient 'Bun.file()' and 'Bun.write()' patterns.
  • Server Configuration Standardization: Verify that HTTP server implementations are using 'Bun.serve()' to leverage Bun's high-performance networking stack.
namebun-patterns
allowed-toolsRead, Grep, Glob

Bun Patterns Verification

Automatically check that backend code uses Bun-specific APIs instead of Node.js patterns.

When to Apply

  • Reviewing files in src/backend/
  • Writing new backend code
  • Checking file I/O operations

Patterns to Enforce

File Operations

Correct (Bun):

// Reading files
const content = await Bun.file(path).text();
const json = await Bun.file(path).json();

// Writing files
await Bun.write(path, content);

// Checking existence
const exists = await Bun.file(path).exists();

Incorrect (Node.js):

// These should NOT be used in backend
import fs from 'fs';
import { readFile, writeFile } from 'fs/promises';
fs.readFileSync(path);

Process and Environment

Correct (Bun):

const port = Bun.env.PORT || 9339;

Incorrect:

const port = process.env.PORT; // Less preferred in Bun

HTTP Server

Correct (Bun):

Bun.serve({
  port: 9339,
  fetch(req) {
    return new Response('OK');
  },
});

Verification Steps

  1. Search for Node.js imports: import fs from, require('fs')
  2. Check file operations use Bun.file() or Bun.write()
  3. Verify WebSocket server uses Bun patterns
  4. Confirm no fs.readFile or fs.writeFile calls

Reference