import { Module } from '@nestjs/common' ; import { TypeOrmModule } from '@nestjs/typeorm' ; import { User } from '../users/user.entity' ; import { ConfigModule , ConfigService } from '@nestjs/config' ; @ Module ( { imports : [ TypeOrmModule . forRootAsync ( { imports : [ ConfigModule ] , useFactory : async ( configService ) => ( { type : 'mysql' , host : configService . get < string > ( 'databaseHost' ) , port : configService . get < number > ( 'databasePort' ) , username : configService . get < string > ( 'databaseUsername' ) , password : configService . get < string > ( 'databasePassword' ) , database : configService . get < string > ( 'databaseName' ) , entities : [ User , ] , } ) , inject : [ ConfigService ] } ) , ] } ) export class DatabaseModule { }