#BunRuntimeModernJavaScriptSkill##WhatThisSkillEnablesClaudecanbuildanddeployJavaScript/TypeScriptapplicationsusingBun,theall-in-oneJavaScriptruntimethat's 3x faster than Node.js for package installs and startup time. Bun includes a native bundler, test runner, package manager, and TypeScript transpiler in a single binary. From APIs to CLIs to build tools, Bun provides drop-in Node.js compatibility with modern performance.## Prerequisites**Required:**- Claude Pro subscription or Claude Code CLI- macOS, Linux, or WSL (Windows support in beta)- curl or wget for installation- Basic JavaScript/TypeScript knowledge**What Claude handles automatically:**- Writing Bun-optimized server code- Configuring bun:test for testing- Setting up Bun.serve() for HTTP servers- Using Bun.build() for bundling- Implementing file operations with Bun.file()- Adding WebSocket support- Configuring environment variables- Optimizing for Bun'sperformancecharacteristics##HowtoUseThisSkill###High-PerformanceHTTPServer**Prompt:**"Create Bun HTTP server with: REST API routes, JSON parsing, CORS middleware, static file serving, WebSocket support, and error handling. Optimize for maximum req/sec."Claudewill:1.UseBun.serve()withfetchhandler2.ImplementroutingwithURLpatterns3.AddCORSheaders4.ServestaticfileswithBun.file()5.SetupWebSocketupgrade6.Handleerrorsgracefully7.Benchmarkwithwrk/autocannon###CLIToolDevelopment**Prompt:**"Build CLI tool with Bun for: file processing, progress bars, colored output, interactive prompts, and parallel operations. Package as standalone binary."Claudewill:1.ParseargswithBun.argv2.Usechalkforcolors3.Addoraforspinners4.Implementinquirerprompts5.ProcessfileswithBun.file()6.UseBun.spawn()forparallel7.Buildexecutablewithbunbuild###DatabaseOperations**Prompt:**"Create Bun app with SQLite using bun:sqlite. Include: connection pooling, prepared statements, migrations, and query builder pattern."Claudewill:1.Usebun:sqlitemodule2.Setupconnectionpool3.Createpreparedstatements4.Implementmigrationsystem5.Buildquerybuilder6.Addtransactionsupport7.Handleerrorsandcleanup###TestingwithBun**Prompt:**"Set up Bun testing for API with: unit tests, integration tests, mocking, coverage reporting, and parallel execution."Claudewill:1.Writetestswithbun:test2.Useexpectassertions3.MockwithspyOn4.Configurecoverage5.Runtestsinparallel6.Addbefore/afterhooks7.TestHTTPendpoints##TipsforBestResults1.**UseBunAPIs**:Prefer`Bun.file()`over`fs`,`Bun.serve()`overhttpmodule.Bun's APIs are optimized and simpler.2. **Native TypeScript**: No need for ts-node or build step. Bun runs TypeScript natively. Use .ts extensions directly.3. **Built-in Bundler**: Use `bun build` instead of webpack/esbuild. Single-command bundling with tree-shaking.4. **Fast Package Manager**: Run `bun install` instead of npm/pnpm. Uses global cache and parallel downloads.5. **WebSocket Native**: Bun.serve() includes WebSocket upgrade. No need for ws or socket.io for simple cases.## Common Workflows### REST API Backend```"Build production REST API with Bun:1. HTTP server with Bun.serve() and routing2. JWT authentication middleware3. Database with bun:sqlite or Postgres4. Request validation with Zod5. Rate limiting with in-memory store6. File uploads with Bun.file()7. WebSocket for real-time updates8. Docker deployment with bun:alpine"```### Build Tool Development```"Create build tool with Bun:1. File watching with Bun.watch()2. Bundling with Bun.build()3. TypeScript transpilation (automatic)4. Minification and tree-shaking5. Source maps generation6. Plugin system for transforms7. Parallel file processing8. Cache invalidation"```### Microservices Infrastructure```"Build microservices with Bun:1. Service discovery with etcd2. gRPC communication3. Health checks endpoint4. Metrics collection5. Structured logging6. Graceful shutdown7. Docker containers8. Kubernetes deployment"```## Troubleshooting**Issue:** "Node.js package not working in Bun"**Solution:** Check Bun compatibility at bun.sh/docs. Most npm packages work. For native modules, ensure Bun version supports Node-API. Use --bun flag or check package.json engines field.**Issue:** "Performance not better than Node.js"**Solution:** Ensure using Bun APIs (Bun.serve not http). Check CPU-bound vs I/O-bound. Bun excels at I/O. Profile with bun:jsc. Verify using latest Bun version.**Issue:** "TypeScript types not working"**Solution:** Install @types packages with bun add -d. Check bunfig.toml has correct compilerOptions. Use bun-types for Bun APIs. Restart editor/LSP.## Learn More- [Bun Official Documentation](https://bun.sh/docs)- [Bun GitHub Repository](https://github.com/oven-sh/bun)- [Bun Discord Community](https://bun.sh/discord)- [Awesome Bun Resources](https://github.com/apvarun/awesome-bun)
Features
Key capabilities and functionality
3x faster package installs with global cache
Native TypeScript support without transpilation
Built-in bundler, test runner, and package manager
Ask Claude: 'Create Bun server for [your use case]'
Run with: bun run server.ts
Use Cases
Common scenarios and applications
High-performance HTTP servers with Bun.serve()
CLI tools with fast startup times
Build tools with native bundling
Troubleshooting
Common issues and solutions
npm package not compatible
Check bun.sh/docs for compatibility. Most packages work. For native modules, verify Bun version supports Node-API. Try --bun flag or update package.
Performance not improved over Node
Use Bun APIs (Bun.serve not http module). Bun excels at I/O-bound tasks. Profile with bun:jsc. Verify latest Bun version installed.
TypeScript types missing
Install @types packages: bun add -d @types/node. Add bun-types for Bun APIs. Check bunfig.toml compilerOptions. Restart LSP.
Usage Examples
Practical code examples demonstrating common use cases and implementation patterns
HTTP Server with Routing
http-server-with-routing.ts
typescript
constserver=Bun.serve({port:3000,asyncfetch(req){consturl=newURL(req.url);// Route handlingif(url.pathname==='/'){returnnewResponse('Hello from Bun!');}if(url.pathname==='/api/users'){constusers=awaitgetUsers();returnResponse.json(users);}// Static file servingif(url.pathname.startsWith('/static/')){constfile=Bun.file(`.${url.pathname}`);returnnewResponse(file);}returnnewResponse('Not Found',{status:404});},});console.log(`Listening on http://localhost:${server.port}`);
SQLite Database Operations
sqlite-database-operations.ts
typescript
import{Database}from'bun:sqlite';constdb=newDatabase('mydb.sqlite');// Create tabledb.run(` CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT UNIQUE NOT NULL )`);// Prepared statement for insertionconstinsert=db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');insert.run('Alice','alice@example.com');// Query with prepared statementconstquery=db.prepare('SELECT * FROM users WHERE id = ?');constuser=query.get(1);console.log(user);// TransactionconstinsertMany=db.transaction((users)=>{for(constuserofusers){insert.run(user.name,user.email);}});insertMany([{name:'Bob',email:'bob@example.com'},{name:'Charlie',email:'charlie@example.com'},]);db.close();
Testing with bun:test
testing-with-bun-test.ts
typescript
import{expect,test,describe,beforeAll,afterAll}from'bun:test';describe('Math operations',()=>{test('addition',()=>{expect(1+1).toBe(2);});test('subtraction',()=>{expect(5-3).toBe(2);});});describe('API tests',()=>{letserver;beforeAll(()=>{server=Bun.serve({port:3001,fetch:()=>newResponse('OK')});});afterAll(()=>{server.stop();});test('server responds',async()=>{constres=awaitfetch('http://localhost:3001');expect(res.status).toBe(200);expect(awaitres.text()).toBe('OK');});});// Run with: bun test
Reviews (0)
Loading reviews...
Get the latest Claude resources
Weekly roundup of the best Claude agents, tools, and guides.