Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference forRoot and forFeature [Nest JS]

I would like to understand the difference between forRoot and forFeature in nest js dynamic modules.

I also would like to understand this difference in the case of the TypeOrm dynamic module used with nestjs.

like image 744
Platus Avatar asked Dec 03 '25 20:12

Platus


1 Answers

From Nest.js Discord,

  • forRoot / forRootAsync: configure a module one time. This is either for a global service, or a re-used configuration internally
  • forFeature / forFeatureAsync: make use of the configuration from forRoot/forRootAsync for a specific provider. This usually creates an injection token.
  • register / registerAsync: a module that can be registered multiple times with different configurations each time.
like image 146
user14082 Avatar answered Dec 05 '25 10:12

user14082



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!