28 Nest JS Events and how to do event driven development in Node Nest JS framework

preview_player
Показать описание
#nodejs #nestjs #javascript

In an event driven development, it's very easy to write your code which is modular in nature. This approach allows you to create independent modules which can do certain actions and then raise an event with a specific payload.

And then, other modules can listen to these events and react to it. However, in this entire thing there is no dependency. If I want to remove a module, then I don't have much of an issue because they are independent in nature.

You can find me on:
Рекомендации по теме
Комментарии
Автор

You can use class constructor to initialize class member variables when you create the instance of the class. Thank you for informative tutorials by the way :).

ex)
export class ResponseAddEvent {
constructor(private userId: number, private optionId: number) {}
}

----

@Post()
async handleQuestionResponse() {
// insert data into the response table

console.log('controller');
this.eventEmitter.emit(
events.RESPONSE_SUBMITTED,
new ResponseAddEvent(1, 3), // userId, optionId
);

return { message: 'Response taken' };
}

ryankim
Автор

how can this events trigger an server side event?? using rxjs to push an event to te client?

facundolucero
Автор

What is the theme in vscode that you are using? I want to try that!

skyzane
Автор

Great video! Trying to reproduce the events in one of my projects, I encountered a problem... The event is only emitted once, but the OnEvent listener is firing twice. Any idea why??

tom_c
Автор

Which VSCODE theme are you using? Can anyone please tell me??

jazimabbas
Автор

Need to add a constructor in ResponseAddEvent, then you can initialize the class in one line.

ms
Автор

This makes sense, however you need to clarify that you're blending CQRS with microservices.

NhileshABaua