Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!