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

@hazeljs/pubsub

v1.0.6

Published

Google Cloud Pub/Sub module for HazelJS framework with decorator-based consumers

Readme

@hazeljs/pubsub

Google Cloud Pub/Sub Module for HazelJS - Publish, Subscribe, and Decorator-Based Consumers

Google Cloud Pub/Sub integration for HazelJS with decorator-based subscriptions, publisher service, and explicit ack() / nack() control.

npm version npm downloads License: Apache-2.0

Features

  • Publish - Send messages to Pub/Sub topics with PubSubPublisherService
  • Consume - Decorator-driven consumers via @PubSubConsumer and @PubSubSubscribe
  • Ack/Nack control - Explicit message acknowledgement APIs in handler payload
  • Auto behavior - Default ack on success and nack on error, overridable globally or per-subscription
  • Subscription bootstrap - Optional auto-creation of subscriptions (with topic)
  • TypeScript - Typed payload contracts and module options

Installation

npm install @hazeljs/pubsub

Quick Start

1. Configure PubSubModule

import { HazelModule } from '@hazeljs/core';
import { PubSubModule } from '@hazeljs/pubsub';

@HazelModule({
  imports: [
    PubSubModule.forRoot({
      projectId: process.env.GCP_PROJECT_ID,
    }),
  ],
})
export class AppModule {}

2. Publish Messages

import { Injectable } from '@hazeljs/core';
import { PubSubPublisherService } from '@hazeljs/pubsub';

@Injectable()
export class OrderService {
  constructor(private readonly publisher: PubSubPublisherService) {}

  async createOrder(order: { id: string; total: number }) {
    await this.publisher.publishJson('orders-topic', order, {
      attributes: { source: 'api' },
    });
  }
}

3. Consume Messages (Decorator-Based)

import { Injectable } from '@hazeljs/core';
import { PubSubConsumer, PubSubSubscribe, PubSubSubscriptionHandlerPayload } from '@hazeljs/pubsub';

@PubSubConsumer({ ackOnSuccess: true, nackOnError: true, parseJson: true })
@Injectable()
export class OrderConsumer {
  @PubSubSubscribe({
    subscription: 'orders-subscription',
    topic: 'orders-topic',
    autoCreateSubscription: true,
  })
  async handleOrder(payload: PubSubSubscriptionHandlerPayload<{ id: string; total: number }>) {
    // process order payload
    console.log(payload.data.id, payload.data.total);

    // Optional manual control:
    // payload.ack();
    // payload.nack();
  }
}

4. Let HazelJS Discover Consumers

import { HazelApp, HazelModule } from '@hazeljs/core';
import { PubSubModule } from '@hazeljs/pubsub';
import { OrderConsumer } from './order.consumer';

@HazelModule({
  imports: [
    PubSubModule.forRoot({
      projectId: process.env.GCP_PROJECT_ID,
    }),
  ],
  providers: [OrderConsumer], // Decorated consumers are discovered from providers
})
class AppModule {}

async function bootstrap() {
  const app = new HazelApp(AppModule);
  await app.listen(3000);
}

bootstrap();

Acknowledgement Behavior

By default:

  • Successful handler execution -> ack()
  • Handler throws -> nack()

You can override this globally via @PubSubConsumer(...) or per subscription via @PubSubSubscribe(...).

You can also return 'ack' or 'nack' from handler methods for explicit behavior.

Async Configuration

import { ConfigService } from '@hazeljs/config';
import { PubSubModule } from '@hazeljs/pubsub';

PubSubModule.forRootAsync({
  useFactory: (config: ConfigService) => ({
    projectId: config.get('GCP_PROJECT_ID'),
    keyFilename: config.get('GOOGLE_APPLICATION_CREDENTIALS'),
  }),
  inject: [ConfigService],
});

Local Emulator

Use the Google Pub/Sub emulator locally:

export PUBSUB_EMULATOR_HOST=localhost:8085

Then configure:

PubSubModule.forRoot({
  projectId: 'local-project',
  apiEndpoint: process.env.PUBSUB_EMULATOR_HOST,
});

API Reference

PubSubPublisherService

  • publish(topicName, data, options?) - Publish string | Buffer | object
  • publishJson(topicName, data, options?) - Publish JSON with content-type: application/json

Decorators

  • @PubSubConsumer(options?) - Class-level defaults (ackOnSuccess, nackOnError, parseJson, autoCreateSubscription)
  • @PubSubSubscribe(options) - Method-level subscription handler metadata
    • subscription - Subscription name (required)
    • topic? - Topic name (required only when autoCreateSubscription: true)
    • autoCreateSubscription? - Auto-create missing subscription
    • parseJson? - Parse message body as JSON
    • ackOnSuccess? - Auto-ack successful handler execution
    • nackOnError? - Auto-nack on thrown error

PubSubModule

  • forRoot(options?) - Sync module config
  • forRootAsync({ useFactory, inject }) - Async module config
  • registerSubscriptionsFromProvider(provider) - Register decorated handlers from an instantiated provider

Requirements

  • Google Cloud Pub/Sub enabled in your GCP project
  • Service account credentials (or emulator)
  • Node.js >= 14