#Convert an event listener function to NestJS decorator

1 messages · Page 1 of 1 (latest)

wooden plover
#

Hello - How do I convert the following code to a nestjs decorator? Basically I want to listen couple of events and handle them respectively. So I want to go from this

client.on('ready', () => {
   console.log('Client is ready!');
});

to this

@On('ready')
clientReady() {
  console.log('Client is ready!');
}

Check here to get full context - https://discord.com/channels/520622812742811698/1056974304920748105

Note: I set up the dynamic module and all works perfectly

boreal folio
#

You'd need to create a new library that scans for the metadata set by the decorators and sets up the event listener. micalevisk already pointed at the NestJS event emitter code base. You can also look at necord for more inspiration

wooden plover
boreal folio
#

From a brief read through, yes