npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@horizon-republic/nestjs-jetstream

v1.0.6

Published

A NestJS transport for NATS JetStream with built-in support for Events and RPC Commands messaging patterns via JetStream.

Readme

NestJs JetStream Transport

A NestJS transport for NATS JetStream with built-in support for Events (fire-and-forget) and Commands (RPC) messaging patterns.

npm version codecov License: MIT

Features

  • 🔄 Full JetStream support: JetStream used for persistence + Core NATS for low-latency replies in RPC
  • 🚀 Dual messaging patterns: Events (pub/sub) and Commands (RPC)
  • 🎯 Type-safe: Full TypeScript support with strict types
  • 📦 Multiple instances: Run multiple services in a single application
  • High performance: Optimized for throughput and low latency
  • 🛡️ Reliable: At-least-once delivery with configurable acknowledgment strategies

ToDo

  • 🔧 Configurable: Extensive stream and consumer configuration options

Installation

npm install @horizon-republic/nestjs-jetstream

Quick Start

Server (Consumer)

Register the module in your app.module.ts:

import {JetstreamServerModule} from '@horizon-republic/nestjs-jetstream'

imports: [
    JetstreamServerModule.forRoot({
        name: 'my_service', // Unique name for the JetStream service. Will be registered as `my_service__microservice``
        servers: ['localhost:4222'], // List of NATS servers to connect to.
    }),
],

Get transport instance in your main.ts:

import {getJetStreamTransportToken, JetstreamTransport} from '@horizon-republic/nestjs-jetstream';

const bootstrap = async () => {
    // ... your code here

    const transport: JetstreamTransport = app.get(getJetStreamTransportToken('my_service'));

    app.connectMicroservice(transport, {inheritAppConfig: true});

    await app.startAllMicroservices();

    // ... app.listen() and etc
};

If everything is set up correctly, you should see the following logs in your console:

[Nest] 98936  - 11/04/2025, 10:25:59 PM     LOG [StreamProvider] Ensure stream requested: my_service__microservice_ev-stream
[Nest] 98936  - 11/04/2025, 10:25:59 PM     LOG [StreamProvider] Ensure stream requested: my_service__microservice_cmd-stream
[Nest] 98936  - 11/04/2025, 10:25:59 PM     LOG [ConnectionProvider] NATS connection established: localhost:4222
[Nest] 98936  - 11/04/2025, 10:25:59 PM     LOG [ConnectionProvider] NATS JetStream manager initialized
[Nest] 98936  - 11/04/2025, 10:25:59 PM   DEBUG [StreamProvider] Checking stream existence: my_service__microservice_ev-stream
[Nest] 98936  - 11/04/2025, 10:25:59 PM   DEBUG [StreamProvider] Checking stream existence: my_service__microservice_cmd-stream
[Nest] 98936  - 11/04/2025, 10:25:59 PM     LOG [StreamProvider] Stream exists, updating: my_service__microservice_ev-stream (subjects: 1)
[Nest] 98936  - 11/04/2025, 10:25:59 PM     LOG [StreamProvider] Stream exists, updating: my_service__microservice_cmd-stream (subjects: 1)
[Nest] 98936  - 11/04/2025, 10:25:59 PM   DEBUG [ConsumerProvider] Consumer exists: my_service__microservice_cmd-consumer
[Nest] 98936  - 11/04/2025, 10:25:59 PM   DEBUG [ConsumerProvider] Consumer exists: my_service__microservice_ev-consumer

Consumer register 2 message handlers and process them independently:

  • my_service__microservice_ev-stream - for events
  • my_service__microservice_cmd-stream - for commands

Message Handlers:

You can register message handlers for events and commands in the same way as you would do for any other NestJS microservice. You can use the @EventPattern and @MessagePattern decorators not only in controllers, but also in other classes as well.

import { EventPattern, MessagePattern, Payload } from '@nestjs/microservices';
import { Controller } from '@nestjs/common';

@Controller()
export class AppMicroserviceController {
    @EventPattern('user.created')
    public handleEvent(@Payload() payload: any) {
        console.log('Received event:', payload);
    }

    @MessagePattern('user.get')
    public handleCommand(@Payload() payload: any) {
        console.log('Received command:', payload);

        return {
            id: 1,
            name: 'John Doe',
        };
    }
}

Client (Publisher)

Register the module in your module:

import { JetstreamClientModule } from '@horizon-republic/nestjs-jetstream';

imports: [
    JetstreamClientModule.forFeature({
        name: 'my_service', // Should match the name of the server module because routing is based on the name
        servers: ['localhost:4222'],
    }),
]

Using the Client:

import { ClientProxy } from '@nestjs/microservices';
import { Controller, Get, Inject } from '@nestjs/common';

@Controller()
export class AppMicroserviceController {
    public constructor(
        @Inject('my_service')
        private readonly myServiceProxy: ClientProxy,
    ) {}

    @Get('send-event')
    public sendEvent() {
        return this.myServiceProxy.emit('user.created', { someData: 'someData' });
    }

    @Get('send-command')
    public sendCommand() {
        return this.myServiceProxy.send('user.get', { id: 1 });
    }
}

Success connection will trigger the following log:

[Nest] 843  - 11/04/2025, 10:37:37 PM     LOG [JetstreamClientProxy] Inbox subscription established: my_service__microservice.PWL9AF1Y7EQKTZ8RSA0V0Y

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

License

MIT © [Your Name]

Links

Support