nestjs-config
nestjs-config copied to clipboard
Use nestjs-config out of services
Issue type:
- [ x] question
nestjs-config version 0.6.3
@nestjs/common+core or other package versions
- @nestjs/common: 7.6.3
- @nestjs/core: 7.6.12
Excepted behavior
I want to use configuration params out of services and main.ts file. Eg in module.ts files to configure @nestjs/jwt module (secret, expiresTime) or in ormconfig file to configure databse. How can I import config in this files ?
you might want to check next out. This will allow you to do this sort of thing
you might want to check next out. This will allow you to do this sort of thing
How can new config be used with app.use in bootsrap file, and does it support env schema validation ?
You can still do it with the current version
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { NestExpressApplication } from '@nestjs/platform-express';
import AppConfig from './config/app.config';
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.useGlobalPipes(
new ValidationPipe({
transform: true,
//forbidNonWhitelisted: true,
whitelist: true,
}),
);
await app.init();
const config = app.get(AppConfig);
await app.listen(config.port || 9000);
}
bootstrap();
This was taken from one of my applications