Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
Get .env variable inside object in the controller NestJS

I created .env

APP_PORT=3001
DEST=C:\data\formations

I have configService:ConfigService in the controller contractor. I want to get DEST for destination from .env in this code.

@UseInterceptors(FileInterceptor('file', {
  storage: diskStorage({
    destination: /*here*/ ,
    filename: (req, file, cb) => {
      const filename: string = path.parse(file.originalname).name.replace(/\s/g, '')
      const extension: string = path.parse(file.originalname).ext
      cb(null, `${filename}${extension}`)
    }
  })
}))

When I use this inside this other object I get an error.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You should use the ConfigModule for getting the environment varible.

Check the document: https://docs.nestjs.com/techniques/configuration

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want to use configuration outside Nest's IoC container, you can try nest-typed-config:

import { selectConfig } from 'nest-typed-config';
import { ConfigModule, FileConfig } from '@/module/config';

const fileConfig = selectConfig(ConfigModule, FileConfig);

@UseInterceptors(FileInterceptor('file', {
  storage: diskStorage({
    destination: fileConfig.destination,
    filename: (req, file, cb) => {
      const filename: string = path.parse(file.originalname).name.replace(/\s/g, '')
      const extension: string = path.parse(file.originalname).ext
      cb(null, `${filename}${extension}`)
    }
  })
}))
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda