notes
2025-11-24 - Initial Research
Overview
Researching the compatibility and practical use of Bun runtime with NestJS framework.
Key Discoveries
Compatibility Breakthrough
- Bun v1.0.3 (September 2023) was the turning point
- Added support for TypeScript’s
emitDecoratorMetadatawhich is essential for NestJS - NestJS relies heavily on decorators for dependency injection, pipes, guards, etc.
Performance Characteristics
- Startup: ~2x faster than Node.js (~50ms vs ~100ms)
- Throughput: Can handle ~2.4k more requests per second
- Latency: ~30ms faster average response time
- Memory: Generally lower memory footprint than Node.js
Limitations Found
-
CLI Support: NestJS
@nestjs/clidoesn’t have Bun as first-class runtime- Ongoing GitHub issue: nestjs/nest#13881
- Users must manually configure Bun execution
-
Type Checking: Bun doesn’t perform TypeScript type checking at runtime
- Must use separate
tsc --noEmitor other type checkers - This is by design for performance
- Must use separate
-
Package Compatibility: Some edge cases with third-party packages
- Core NestJS packages work well
- Optional dependencies need to handle missing gracefully
- Most npm packages work fine, but some may need workarounds
-
Distribution: When building for npm distribution
- Use
bun build --packages externalto keep dependencies separate - Allows users with Node.js to run the package
- Alternative: standalone Bun executables
- Use
Community Solutions
Multiple starter templates have emerged:
- bunest (dung204) - Most comprehensive, includes modern setup
- bun-nest-starter (Netoun) - Includes Drizzle ORM integration
- bun-nestjs (letstri) - Simple, minimal example
Performance Trade-offs vs Node.js
| Factor | Bun | Node.js |
|---|---|---|
| Startup Speed | ⚡⚡⚡ | ⚡⚡ |
| Runtime Latency | ⚡⚡⚡ | ⚡⚡ |
| Type Safety | ⚠️ Manual | ✅ Built-in |
| Ecosystem Maturity | 🟡 Emerging | ✅ Mature |
| CLI Tool Support | 🟡 Limited | ✅ Excellent |
| Production Readiness | ✅ Yes | ✅ Yes |
Use Cases for Bun + NestJS
Good Fit:
- High-performance API servers (latency-sensitive)
- New projects without legacy dependencies
- Performance-critical microservices
- Projects that need fast startup (serverless functions)
Consider Node.js:
- Large existing ecosystems with many custom packages
- Projects requiring advanced TypeScript IDE support during runtime
- Teams with strong Node.js expertise
- Strict requirement for CLI tool compatibility
Next Steps to Explore
- Create a minimal Bun + NestJS example project
- Benchmark actual performance with database queries
- Test integration with common NestJS packages (TypeORM, Prisma, etc.)
- Investigate Docker containerization with Bun
- Document migration path from Node.js to Bun