Typescript Node.js client for NATS streaming server

Usage no npm install needed!

<script type="module">
  import adhityanGcNats from 'https://cdn.skypack.dev/@adhityan/gc-nats';



A TypeScript Node.js wrapper service for the NATS streaming server based on stan.js client.

Publishing messages

import "reflect-metadata";
import { JsonController, Get, Res } from 'routing-controllers';
import { Inject, Service } from 'typedi';
import { ResponseUtil } from '@app/utils';
import { NatsService } from '@buzzkey/gc-nats';
import { Logger } from '@adhityan/gc-logger';

export class PingController {
  public natsService: NatsService;

  async ping(@Res() res: any) {
    // send test ping message to queue
    const channel: string = "ping";
    const message: any = {
      info: "testing ping"

    const messageId: string = await this.natsService.publish(channel, message);
    Logger.debug(`published message: ${messageId}`);

    return ResponseUtil.ok({ message: 'Ping Successful' }, res);

Subscribing to messages from a channel/subject

import { natsConfig } from '@app/config/nats.config';
import { Logger } from '@adhityan/gc-logger';
import { Worker } from '@adhityan/gc-nats';

const subject = "ping";

export class PingWorker {
    static channel: string = subject;

    public async messageReceived (message: T) {
        Logger.debug('Ping successful. worker processing message: ', message);