Home > Blockchain >  NestJS HTTP Module needs to be imported in every feature module
NestJS HTTP Module needs to be imported in every feature module

Time:04-05

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.

CodePudding user response:

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

  • Related