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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@savanapoint/nestjs-pubsub

v0.0.4

Published

A library for integrating Firebase Pub/Sub with NestJS.

Downloads

3

Readme

@savanapoint/nestjs-pubsub

A library for integrating Firebase Pub/Sub with NestJS.

Installation

To install the library in your project, use the following command:

npm install @savanapoint/nestjs-pubsub
# or
yarn add @savanapoint/nestjs-pubsub

Configuration

Firebase Configuration

Ensure that you have your Firebase credentials set up. You can use environment variables to provide these credentials.

Example environment variables (.env):

FIREBASE_API_KEY=your_api_key
FIREBASE_AUTH_DOMAIN=your_auth_domain
FIREBASE_PROJECT_ID=your_project_id
FIREBASE_STORAGE_BUCKET=your_storage_bucket
FIREBASE_MESSAGING_SENDER_ID=your_sender_id
FIREBASE_APP_ID=your_app_id

Importing and Configuring the Module

In your main module or in the module where you want to use the PubSubService, import and configure the PubSubModule:

src/app.module.ts

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { PubSubModule } from '@savanapoint/nestjs-pubsub';

@Module({
  imports: [
    ConfigModule.forRoot(), // Loads environment variables
    PubSubModule.forRoot({
      apiKey: process.env.FIREBASE_API_KEY,
      authDomain: process.env.FIREBASE_AUTH_DOMAIN,
      projectId: process.env.FIREBASE_PROJECT_ID,
      storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
      messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
      appId: process.env.FIREBASE_APP_ID,
    }),
  ],
  // Other modules and controllers
})
export class AppModule {}

Using PubSubService

Subscribing to a Channel

To receive messages from a channel, use the subscribe method of the PubSubService.

Example usage in a service:

src/notification-service/notification-service.service.ts

import { Injectable, OnModuleInit } from '@nestjs/common';
import { PubSubService } from '@savanapoint/nestjs-pubsub';

@Injectable()
export class NotificationService implements OnModuleInit {
  constructor(private readonly pubSubService: PubSubService) {}

  onModuleInit() {
    this.pubSubService.subscribe('my-channel', ['subscriber-id'], (message) => {
      console.log('New message received:', message);
    });
  }
}

Publishing Messages

To publish messages to a channel, use the publish method of the PubSubService.

Example usage in a controller:

src/notification-controller/notification.controller.ts

import { Controller, Post, Body } from '@nestjs/common';
import { PubSubService } from '@savanapoint/nestjs-pubsub';

@Controller('notifications')
export class NotificationController {
  constructor(private readonly pubSubService: PubSubService) {}

  @Post('send')
  async sendNotification(
    @Body('channel') channel: string,
    @Body('message') message: string,
    @Body('subscribers') subscribers: string[],
  ): Promise<void> {
    await this.pubSubService.publish(channel, message, subscribers);
  }
}

Contribution

If you want to contribute to this library, follow these steps:

  1. Fork the repository.
  2. Create a branch for your feature (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Create a pull request.

License

This library is licensed under the MIT License.