Monday 28 September 2020

Initialize using constructor or lifecycle hook

We use Nest.js as our server framework.As part of the constructor for a module, I set up an event listener. Just a real quick two-liner synchronous process. My co-worker said that I should use the onModuleInit lifecycle hook. But I couldn't find any good evidence either way. It seemed that onModuleInit is mainly useful for async operations whereas small sync setup can happen inside the constructor. What's your opinion?

Submitted September 29, 2020 at 07:06AM by the_bronze_burger

No comments:

Post a Comment