
bun-patterns
Verify Bun-specific patterns in backend code. Use when reviewing or writing backend TypeScript files
by Grips001|Open Source
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
- Search for Node.js imports:
import fs from,require('fs') - Check file operations use
Bun.file()orBun.write() - Verify WebSocket server uses Bun patterns
- Confirm no
fs.readFileorfs.writeFilecalls
Reference
- Bun File I/O
- Bun HTTP Server
- Project Rule 2 in CLAUDE.md