Home > other >  if everything in node is a module than what is the point of modules in NestJs?
if everything in node is a module than what is the point of modules in NestJs?

Time:01-02

why not simply use folders instead of modules if the only purpose is to make the structure more organized?

It is weird because it does not seem necessary since every file is a separate module in node js and if i need anything i have to import it using the import statement anyways so what is the point of specifying the imports and exports in a module? does it affect the dependency injection if i just import what i need without using modules(@Module decorator) or something similar?

CodePudding user response:

NestJs has opted to design their framework with dependency injection as one of its core principals. Ie, you write your code just using the name/type of the services you want to use, and then a different piece of code is responsible for finding that service, knowing how to construct it, and then passing it in to you.

Native import/export doesn't have a system for dependency injection, so the main thing that the @Module decorator does is organize the metadata needed for the injector system.

  • Related