简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM