{"id":17888652,"url":"https://github.com/trs/nestjs-events","last_synced_at":"2025-04-03T03:16:07.825Z","repository":{"id":87522841,"uuid":"606579993","full_name":"trs/nestjs-events","owner":"trs","description":"Alternative event module for NestJS.","archived":false,"fork":false,"pushed_at":"2024-02-08T19:51:33.000Z","size":1033,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-26T11:12:02.457Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-02-25T22:57:45.000Z","updated_at":"2023-10-06T16:16:19.000Z","dependencies_parsed_at":"2023-03-18T14:27:00.835Z","dependency_job_id":"d9536a49-96bf-4f30-81e8-be14c03e9f60","html_url":"https://github.com/trs/nestjs-events","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trs%2Fnestjs-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trs%2Fnestjs-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trs%2Fnestjs-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trs%2Fnestjs-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trs","download_url":"https://codeload.github.com/trs/nestjs-events/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246927843,"owners_count":20856198,"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":["hacktoberfest"],"created_at":"2024-10-28T13:42:03.415Z","updated_at":"2025-04-03T03:16:07.792Z","avatar_url":"https://github.com/trs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS Events\n\nAlternative event module for NestJS.\n\n## Install\n\n```sh\nyarn add nestjs-events\n```\n\n`nestjs-events` works with NestJS (9 or 10) and RxJS 7, ensure your have those installed.\n\n```sh\nyarn add @nestjs/common@^10 rxjs@^7\n```\n\n## Usage\n\nRegister the event module in your app to be available globally\n\n```ts\nimport { Module } from \"@nestjs/common\";\nimport { EventModule } from \"nestjs-events\";\n\n@Module({\n  imports: [\n    EventModule.forRoot({\n      prefix: \"\", // optional\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\nOr only for a specific module\n\n```ts\nimport { Module } from \"@nestjs/common\";\nimport { EventModule } from \"nestjs-events\";\n\n@Module({\n  imports: [\n    EventModule.register({\n      prefix: \"\", // optional\n    }),\n  ],\n})\nexport class MyOtherModule {}\n```\n\nDeclare your events.\n\n```ts\nexport class MyEvent {\n  public readonly value: number;\n  public readonly other: string;\n\n  constructor(parameters: { value: number; other: string }) {\n    this.value = parameters.value;\n    this.other = parameters.other;\n  }\n}\n```\n\nYou can also use the `EventBuilder` helper.\n\n```ts\nimport { EventBuilder } from \"nestjs-events\";\n\nexport class MyEvent extends EventBuilder\u003c{ value: number; other: string }\u003e() {}\n```\n\nEmit events with the `EventService`.\n\n```ts\nimport { Injectable } from \"@nestjs/common\";\nimport { EventService } from \"nestjs-events\";\n\nimport { MyEvent } from \"./my-event.event.ts\";\n\n@Injectable()\nexport class MyService {\n  constructor(private readonly eventService: EventService) {}\n\n  someMethod() {\n    this.eventService.emit(new MyEvent({ value: 1, other: \"hello\" }));\n  }\n}\n```\n\nListen to events through the `@OnEvent` decorator.\n\n```ts\nimport { Injectable } from \"@nestjs/common\";\nimport { OnEvent } from \"nestjs-events\";\n\nimport { MyEvent } from \"./my-event.event.ts\";\n\n@Injectable()\nexport class MyService {\n  @OnEvent(MyEvent)\n  handleMyEvent(event: MyEvent) {\n    // event.value\n    // event.other\n  }\n}\n```\n\nYou can subscribe to events as well, returning an Observable.\n\n```ts\nimport { Injectable } from \"@nestjs/common\";\nimport { OnEvent } from \"nestjs-events\";\n\nimport { MyEvent } from \"./my-event.event.ts\";\n\n@Injectable()\nexport class MyService {\n  constructor(private readonly eventService: EventService) {}\n\n  someMethod() {\n    eventService.on(MyEvent).pipe().subscribe();\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrs%2Fnestjs-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrs%2Fnestjs-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrs%2Fnestjs-events/lists"}