Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nestjs-config out of services #367

Open
timofeyp opened this issue Mar 14, 2021 · 3 comments
Open

Use nestjs-config out of services #367

timofeyp opened this issue Mar 14, 2021 · 3 comments

Comments

@timofeyp
Copy link

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 ?

@bashleigh
Copy link
Collaborator

you might want to check next out. This will allow you to do this sort of thing

@timofeyp
Copy link
Author

timofeyp commented Jun 3, 2021

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 ?

@bashleigh
Copy link
Collaborator

bashleigh commented Jun 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants