import { Module } from '@nestjs/common' ; import { MongooseModule } from '@nestjs/mongoose' ; import { AppController } from './app.controller' ; import { AppService } from './app.service' ; import { SharedModule } from './shared/shared.module' ; import { ConfigurationService } from './shared/configuration/configuration.service' ; import { UserModule } from './user/user.module' ; import { AuthModule } from './auth/auth.module' ; @ Module ( { imports : [ SharedModule , MongooseModule . forRootAsync ( { useFactory : async ( configService ) => ( { uri : configService . mongoUri , useNewUrlParser : true , } ) , inject : [ ConfigurationService ] , } ) , UserModule , AuthModule , ] , controllers : [ AppController ] , providers : [ AppService ] , } ) export class AppModule { static port : number | string ; static isDev : boolean ; constructor ( private readonly _configurationService ) { AppModule . port = AppModule . normalizePort ( _configurationService . port ) ; AppModule . isDev = _configurationService . isDevelopment ; } param val private static normalizePort ( val ) { const port = typeof val === 'string' ? parseInt ( val , 10 ) : val ; if ( Number . isNaN ( port ) ) { return val ; } if ( port >= 0 ) { return port ; } throw new Error ( `Port "${ val }" is invalid.` ) ; } }