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):
typescript
// 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):
typescript
// 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):
typescript
const port = Bun.env.PORT || 9339;
Incorrect:
typescript
const port = process.env.PORT; // Less preferred in Bun
HTTP Server
Correct (Bun):
typescript
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