{"id":16351525,"url":"https://github.com/onhate/nest-events","last_synced_at":"2026-03-15T23:03:39.296Z","repository":{"id":188127213,"uuid":"678145191","full_name":"onhate/nest-events","owner":"onhate","description":"It's the same as @nestjs/event-emitter but allowing you to implement your own emitter, like AWS SNS, RabbitMQ.","archived":false,"fork":false,"pushed_at":"2023-12-14T19:02:31.000Z","size":211,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-27T18:55:33.470Z","etag":null,"topics":["eventbridge","eventemitter2","events","lambda","module","nestjs","pubsub","sns","sqs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onhate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-13T20:38:15.000Z","updated_at":"2024-08-16T14:28:59.000Z","dependencies_parsed_at":"2023-10-14T20:35:56.289Z","dependency_job_id":"addfd4e3-b113-4387-b8b8-52de8df176c7","html_url":"https://github.com/onhate/nest-events","commit_stats":null,"previous_names":["onhate/nest-events"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/onhate/nest-events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onhate","download_url":"https://codeload.github.com/onhate/nest-events/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-events/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262728051,"owners_count":23354688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eventbridge","eventemitter2","events","lambda","module","nestjs","pubsub","sns","sqs"],"created_at":"2024-10-11T01:09:34.344Z","updated_at":"2026-03-15T23:03:39.208Z","avatar_url":"https://github.com/onhate.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nest Events @Emitter\n\nWelcome to the Nest Events library! This library provides event handling and emitting capabilities for\nyour [NestJS](https://nestjs.com/) applications. With Nest Events, you can easily manage and trigger events within your\napplication, making it simpler to implement various communication patterns and workflows.\n\nIt's the same as `@nestjs/event-emitter` but allowing you to implement your own emitter, like AWS SNS, RabbitMQ, etc.\nA default emitter is already provided by default using [EventEmitter2](https://github.com/EventEmitter2/EventEmitter2).\n\n## Installation\n\nTo get started with Nest Events, you need to install the library using [npm](https://www.npmjs.com/)\nor [yarn](https://yarnpkg.com/). Open your terminal and run the following command:\n\n```bash\nnpm install nest-events\n```\n\nor\n\n```bash\nyarn add nest-events\n```\n\n## Usage\n\n### Importing the Module\n\nTo start using the Nest Events library, you need to import the `EventBusModule` into your NestJS application. In your\nmodule file (e.g., `app.module.ts`), import the module like this:\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { EventBusModule } from 'nest-events';\n\n@Module({\n  imports: [EventBusModule.forRoot()],\n})\nexport class AppModule {}\n```\n\n### Emitting Events\n\nYou can emit events using the `EventBus` service provided by the library. Here's how you can emit an event:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { EventBus } from 'nest-events';\n\n@Injectable()\nexport class MyService {\n  constructor(private readonly eventBus: EventBus) {\n  }\n\n  async doSomething() {\n    // ... your logic\n\n    // Emit an event\n    await this.eventBus.emitAsync('myEvent', eventData);\n  }\n}\n```\n\n### Handling Events\n\nTo handle events, you can use decorators provided by the library. Here's an example of how to use the `@On` decorator to\nhandle an event:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { On } from 'nest-events';\n\n@Injectable()\nexport class MyEventHandler {\n  @On('myEvent')\n  handleMyEvent(eventData: any) {\n    // Handle the event\n    console.log('Event received:', eventData);\n  }\n}\n```\n\n### Custom Emitters\n\nNest Events allows you to work with multiple emitters for different scenarios. You can define custom emitters and use\nthem accordingly.\n\n```typescript\nimport { DefaultEventEmitter, Emitter, EventBus, On } from 'nest-events';\n\n@Emitter('cloud')\nexport class CloudEmitter extends DefaultEventEmitter {\n  private sns: SNS;\n\n  constructor() {\n    super();\n    this.sns = new SNS();\n  }\n\n  async emitAsync(event: string, message: any): Promise\u003cboolean\u003e {\n    try {\n      const params = {\n        Message: JSON.stringify(message),\n        TopicArn: 'arn:aws:sns:us-east-1:123456789012:MyTopic'\n      };\n      await this.sns.publish(params).promise();\n      return true;\n    } catch (error) {\n      console.error('Error emitting event:', error);\n      return false;\n    }\n  }\n}\n\n@Injectable()\nexport class MyService {\n  constructor(private readonly eventBus: EventBus) {\n  }\n\n  async doSomething() {\n    // ... your logic\n\n    // Emit an event using the custom emitter\n    await this.eventBus.emitter('cloud').emitAsync('myEvent', eventData);\n  }\n}\n\n@Injectable()\nexport class MyListener {\n  @On('myEvent')\n  handleCustomEvent(eventData: any) {\n    // Handle the event from the custom emitter\n    console.log('Custom event received:', eventData);\n  }\n}\n```\n\n## Configuration\n\nThe `EventBusModule.forRoot()` method accepts an optional configuration object.\nSee [EventEmitter2](https://github.com/EventEmitter2/EventEmitter2) for more configuration options details.\nHere's an example of how to use it:\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { EventBusModule } from 'nest-events';\n\n@Module({\n  imports: [\n    EventBusModule.forRoot({\n      global: true // Set to \"true\" (default) to register as a global module\n      /* Additional configuration options from eventemitter2 can be added here */\n    })\n  ]\n})\nexport class AppModule {}\n```\n\n## Contributing\n\nWe welcome contributions to the Nest Events library! If you find a bug, have a feature request, or want to improve the\ndocumentation, please [open an issue](https://github.com/onhate/nest-events)\nor [submit a pull request](https://github.com/onhate/nest-events).\n\n## License\n\nThis library is released under the [MIT License](https://opensource.org/licenses/MIT).\n\n---\n\nHappy event handling with Nest Events! 🎉\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonhate%2Fnest-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonhate%2Fnest-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonhate%2Fnest-events/lists"}