📝App Host
The module that provides the access to the NestJS application instance.
Imports
import { AppHostService } from 'niro-health';
Method of Use
To use this module, you need to import it at least once in your main module. This way, you can inject it into the remaining modules without having to import it again.
In the example below, I am importing the module and also the service.
import { Module } from '@nestjs/common';
import { AppHostModule, AppHostService } from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [AppHostModule],
controllers: [AppController],
providers: [
AppService,
{
provide: 'IAppHostService',
useClass: AppHostService,
},
],
})
export class AppModule {}
Injecting the module into our service.
import { Inject, Injectable } from '@nestjs/common';
import type { IAppHostService } from 'niro-health';
@Injectable()
export class AppService {
constructor(
@Inject('IAppHostService')
private readonly appHostService: IAppHostService,
) {}
getUrl() {
return this.appHostService.getUrl();
}
}
Global
This module is global, you only need to import it once in the main module. After that, you can inject the service without importing it in the other modules.
Without dependencies
You won't need to connect the pieces with any other module.
Properties
app
static
The NestJS application instance.
Methods
setApp
public
Set the NestJS application instance.
getHttpServer
public
Returns the underlying native HTTP server.
getHttpAdapter
public
Returns the underlying HTTP adapter.
getMicroservices
public
Returns array of the microservices connected to the NestApplication.
getUrl
public
Returns the url the application is listening at, based on OS and IP version. Returns as an IP value either in IPv6 or IPv4
Last updated