C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

Distributed

Microservices

Scale your application using CanxJS microservices. Support for multiple transport layers.

Transporters

Support for TCP, Redis, NATS, MQTT, and Kafka.

Distributed

Build scalable microservice architectures.

Client Proxy

Easily communicate between services.

Hybrid Apps

Run HTTP and Microservices in the same app.

Bootstrap

main.ts
1import { createApp, MicroserviceOptions, Transport } from "canxjs";
2
3async function bootstrap() {
4 const app = createApp();
5
6 // Connect Microservice strategy
7 app.connectMicroservice<MicroserviceOptions>({
8 transport: Transport.TCP,
9 options: {
10 host: 'localhost',
11 port: 3001
12 }
13 });
14
15 await app.startAllMicroservices();
16}

Message Handlers

math.controller.ts
1import { Controller } from "canxjs";
2import { MessageHandler, EventHandler } from "canxjs/microservices";
3
4@Controller()
5export class MathController {
6
7 // Request-Response pattern
8 @MessageHandler({ cmd: 'sum' })
9 accumulate(data: number[]): number {
10 return (data || []).reduce((a, b) => a + b);
11 }
12
13 // Event pattern (Fire and forget)
14 @EventHandler('user_created')
15 handleUserCreated(data: Record<string, unknown>) {
16 console.log('User created event received', data);
17 }
18}

Client Proxy

user.service.ts
1import { ClientProxy, ClientProxyFactory, Transport } from "canxjs/microservices";
2
3export class UserService {
4 private client: ClientProxy;
5
6 constructor() {
7 this.client = ClientProxyFactory.create({
8 transport: Transport.TCP,
9 options: { port: 3001 }
10 });
11 }
12
13 getSum(numbers: number[]) {
14 return this.client.send({ cmd: 'sum' }, numbers);
15 }
16}