Claude Code के साथ Bun
Claude Code का उपयोग करके Bun के बारे में जानें। Practical tips और code examples शामिल हैं।
Claude Code से Bun Runtime के Usage को Accelerate करें
Bun JavaScript/TypeScript का all-in-one runtime है। Package manager, bundler, test runner built-in हैं और Node.js से कई गुना fast चलता है। Claude Code का उपयोग करके Bun की powerful features को efficiently adopt करें।
Project Startup
> Bun से नया web app project बनाओ।
> TypeScript, Hono framework, test setup include करो।
bun init my-app
cd my-app
bun add hono
// src/index.ts
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { logger } from 'hono/logger';
const app = new Hono();
app.use('*', logger());
app.use('/api/*', cors());
app.get('/api/health', (c) => {
return c.json({ status: 'ok', runtime: 'bun' });
});
app.get('/api/users/:id', async (c) => {
const id = c.req.param('id');
const user = await getUser(id);
return c.json(user);
});
export default {
port: 3000,
fetch: app.fetch,
};
Bun Built-in APIs का उपयोग
> Bun के file operation API और SQLite का उपयोग करके
> simple data store implement करो।
// src/db.ts
import { Database } from 'bun:sqlite';
const db = new Database('app.db', { create: true });
db.run(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
export const createUser = db.prepare(
'INSERT INTO users (name, email) VALUES ($name, $email)'
);
export const getUser = db.prepare(
'SELECT * FROM users WHERE id = $id'
);
// Bun file operations
export async function saveUpload(file: File) {
const path = `./uploads/${file.name}`;
await Bun.write(path, file);
return path;
}
export async function readConfig() {
const file = Bun.file('./config.json');
return await file.json();
}
Tests Run करना
Bun में fast test runner built-in है।
> API endpoints के tests लिखो।
> Bun के test runner use करो।
// src/index.test.ts
import { describe, expect, it, beforeAll, afterAll } from 'bun:test';
describe('API endpoints', () => {
it('GET /api/health returns ok', async () => {
const res = await fetch('http://localhost:3000/api/health');
const data = await res.json();
expect(res.status).toBe(200);
expect(data.status).toBe('ok');
});
it('GET /api/users/:id returns user', async () => {
const res = await fetch('http://localhost:3000/api/users/1');
expect(res.status).toBe(200);
const user = await res.json();
expect(user).toHaveProperty('name');
});
});
# Test run
bun test
# Watch mode
bun test --watch
# Coverage
bun test --coverage
Bundle और Build
> Frontend code को Bun से bundle करो।
> Tree-shaking और minify भी enable करो।
// build.ts
await Bun.build({
entrypoints: ['./src/client/index.tsx'],
outdir: './dist',
target: 'browser',
minify: true,
splitting: true,
sourcemap: 'external',
define: {
'process.env.NODE_ENV': '"production"',
},
});
console.log('Build complete!');
Summary
Bun अपनी overwhelming speed और integrated toolchain से development experience को significantly improve करता है। Claude Code के साथ combine करने पर Bun-specific APIs और patterns भी quickly सीखे जा सकते हैं। API Development Guide और Testing Strategy भी reference करें।
Bun की details के लिए Bun Official Documentation देखें।
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।