My app has a main configuration expressed through environment variables (process.env). How can I expose it as one object using Next.js? In the code example below, I am able to retrieve values by keys. However, since I am passing a string, TypeScript is not utilized here.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from '@nestjs/config';
import { envVarsValidator } from "../interfaces/Config";
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
validationSchema: envVarsValidator,
})
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
import { ConfigService } from "@nestjs/config";
@Injectable()
export class AppService {
constructor(private configService: ConfigService) {}
getHello(): string {
return this.configService.get<string>('hello'); // not what I need;
}
}
Pseudocode for what I need:
export class SomeService {
constructor(private configService: ConfigService) {}
someLogic(): any {
const port = this.configService.config.port;
// What I need is one main config object with highlighted properties available on this object via TypeScript
}
}