Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda