Official package · Frameworks

Realtime events for NestJS, the Nest way

A global module that publishes events, authorizes private and presence channels with decorated provider methods, and receives signed webhooks. pusher-js, Laravel Echo and the mobile Pusher SDKs connect unchanged.

  • HibiraService publishes events, reads channels and presence members, and sends to signed-in users.
  • @HibiraChannel() authorizes channels like Laravel’s routes/channels.php, @Broadcast() publishes what a route returns, and @OnHibiraWebhook() receives webhooks in any provider.
  • stream() sends LLM output to a channel, requestApproval() asks a person before your code acts, and HibiraPushService sends push notifications. Nest 10 to 12, on Express or Fastify.

Sign in to see these snippets with your own cluster host. Sign in

  1. Install

    npm install @hibira-io/nestjs
    
    # .env
    HIBIRA_APP_ID=YOUR_APP_ID
    HIBIRA_KEY=YOUR_APP_KEY
    HIBIRA_SECRET=YOUR_APP_SECRET
    HIBIRA_HOST=ws.hibira.io
  2. Set it up

    // app.module.ts
    import { Module } from '@nestjs/common';
    import { HibiraModule } from '@hibira-io/nestjs';
    import { JwtAuthGuard } from './auth/jwt-auth.guard';
    
    @Module({
      imports: [
        HibiraModule.forRoot({
          auth: { guards: [JwtAuthGuard] }, // POST /hibira/auth
          webhooks: true, // POST /hibira/webhook
        }),
      ],
    })
    export class AppModule {}
  3. Use it

    @Injectable()
    export class OrdersService {
      constructor(private readonly hibira: HibiraService) {}
    
      async ship(order: Order) {
        await this.hibira.trigger(`private-orders.${order.id}`, 'order.shipped', { id: order.id });
      }
    
      @HibiraChannel('private-orders.{orderId}')
      async canSeeOrder(user: User, { orderId }: { orderId: string }) {
        return (await this.find(orderId))?.customerId === user.id;
      }
    }

Before you start

  • The app secret is shown only once, when you create the app or rotate its secret. Keep it on your server, never in a browser or game build.
  • For webhooks, create the app with rawBody: true in main.ts, so signatures are checked against the exact bytes received.

Use the app key from your dashboard; the secret stays on your server. Channels, events and authorization endpoints work exactly as they do with Pusher. Create your free account →