Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

nestjs mongoose with config

// app.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config'
import { MongooseModule } from '@nestjs/mongoose';

@Module({
  import: [
    MongooseModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (config: ConfigService) => ({
       	uri: config.get<string>('MONGODB_URI'), // Loaded from .ENV
      })
    })
  ],
})
export class AppModule {}
 
PREVIOUS NEXT
Tagged: #nestjs #mongoose #config
ADD COMMENT
Topic
Name
3+9 =