In nestjs the http module needs to be imported into every feature module. Is there any way to import the http module only once throughout the full application?
Although in all the feature modules the http configurations are the same, why do we need to import and configure in each one.
Thanks.
You could make a global module that imports it and exports it like so:
@Global()
@Module({
  imports: [HttpModule.register(httpModuleOptions)],
  exports: [HttpModule],
})
export class GlobalHttpModule {}
Now import it in the AppModule and you can use HttpService anywhere
If you don't want to create a wrapper module, you can also:
@Module({
  imports: [
    {
      ...HttpModule.register(httpModuleOptions),
      global: true
    }
  ],
})
export class AppModule {}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With