Start United States USA — software How To Emit and Listen to Events Using The NestJS Event Emitter?

How To Emit and Listen to Events Using The NestJS Event Emitter?

186
0
TEILEN

In this post, we’ll look at how to use the NestJS Event Emitter package to emit and listen to events that come in handy in decoupled application part situations
Join the DZone community and get the full member experience. Many times we need to decouple different parts of our application and still want communication between these parts. Events come in quite handy in such situations. In this post, we will look at how to use the NestJS Event Emitter. NestJS has its own Event Emitter package. It provides a simple observer implementation. This allows us to subscribe and listen to various events. So let’s dive right in. The first step is to actually install the required package in our project. This can be done using the below command. Once the installation is successful, we need to import the package in the app.module.ts of our project. See the below example: Here, we import the EventEmitter in the imports array. The forRoot() call initializes the event emitter. It also registers any declarative event listeners that might exist within the application.

Continue reading...