connect to the database
This commit is contained in:
@@ -1,9 +1,28 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import Configuration from './config/configuration';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
load: [Configuration],
|
||||
isGlobal: true,
|
||||
}),
|
||||
MongooseModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: async (config: ConfigService) => ({
|
||||
uri: `mongodb://${config.get<string>(
|
||||
'database.url',
|
||||
)}:${config.get<number>('database.port')}/${config.get<string>(
|
||||
'database.name',
|
||||
)}`,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user