bun-server-quickstart
Bun Server Quick Start
Prerequisites
- Bun ≥
1.3.3
Critical Configuration
tsconfig.json (Required)
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Critical: Both experimentalDecorators and emitDecoratorMetadata must be enabled, otherwise dependency injection will fail.
Minimal Application
import { Application, Controller, GET, Injectable } from "@dangao/bun-server";
@Injectable()
class HealthService {
ping() {
return { status: "ok" };
}
}
@Controller("/api")
class HealthController {
constructor(private readonly service: HealthService) {}
@GET("/health")
check() {
return this.service.ping();
}
}
const app = new Application({ port: 3100 });
app.getContainer().register(HealthService);
app.registerController(HealthController);
app.listen();
Modular Application
import {
Application,
Module,
Controller,
GET,
Injectable,
ConfigModule,
} from "@dangao/bun-server";
@Injectable()
class UserService {
getUsers() {
return [{ id: 1, name: "Alice" }];
}
}
@Controller("/users")
class UserController {
constructor(private readonly userService: UserService) {}
@GET("/")
list() {
return this.userService.getUsers();
}
}
@Module({
imports: [ConfigModule.forRoot({ defaultConfig: {} })],
controllers: [UserController],
providers: [UserService],
})
class AppModule {}
const app = new Application({ port: 3100 });
app.registerModule(AppModule);
app.listen();
Recommended Project Structure
src/
├── main.ts # Entry point
├── app.module.ts # Root module
├── users/
│ ├── user.module.ts
│ ├── user.controller.ts
│ └── user.service.ts
└── common/
└── middleware/
Common Imports
// Core
import { Application, Controller, Module, Injectable } from "@dangao/bun-server";
// HTTP decorators
import { GET, POST, PUT, DELETE, PATCH } from "@dangao/bun-server";
// Parameter decorators
import { Body, Query, Param, Header, Ctx } from "@dangao/bun-server";
// DI
import { Inject, Scope, SCOPE } from "@dangao/bun-server";
// Modules
import {
ConfigModule,
EventModule,
LoggerModule,
SecurityModule,
} from "@dangao/bun-server";
Run Commands
# Install dependencies
bun install
# Run application
bun run src/main.ts
# Run tests (in package directory)
bun --cwd=packages/bun-server test
Next Steps
More from dangaogit/bun-server-skills
bun-server-best-practices
MUST be used for Bun Server tasks. Covers project setup, DI, controllers, modules, middleware, validation, error handling, official modules, Platform Adapter (v3.0+), and AI modules (v2.0+). Load for any Bun Server, @dangao/bun-server, decorator-driven DI, or framework-related work. ALWAYS follow the workflow steps below.
21bun-server-di
Dependency injection guide for Bun Server framework. Use when working with DI container, @Injectable, @Inject decorators, service registration, scopes (singleton/transient/scoped), or Symbol+Interface pattern.
2bun-server-cache
Caching guide for Bun Server framework. Use when implementing caching, using CacheModule, @Cacheable decorator, cache eviction, Redis cache, or improving performance.
2bun-server-websocket
WebSocket guide for Bun Server framework. Use when implementing real-time features, creating WebSocket gateways, handling WebSocket connections, messages, or building chat applications.
2bun-server-events
Event system guide for Bun Server framework. Use when implementing event-driven architecture, using EventModule, @OnEvent decorator, event emitters, or pub/sub patterns.
2bun-server-microservice
Microservice guide for Bun Server framework. Use when building microservices, service discovery, config center, load balancing, circuit breaker, distributed tracing, or inter-service communication.
2