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

212
Views
Environment variable always returns as undefined in NestJS

When I call process.env.MAILHOST which is in the .env it always returns undefined but if it's inside the project's src folder it returns the value that is informed

D:\Projetos\login-jwt\login-jwt\configs\mailer.config.ts

console.log('mail',process.env.MAILHOST);

return undefined

but on D:\Projetos\login-jwt\login-jwt\src\main.ts

app.listen(process.env.PORT);main.ts it finds the right value which is port 3000

D:\Projetos\login-jwt\login-jwt.env.env

PORT=3000
MAILHOST=smtp.gmail.com
MAILSERVICE=Gmail
MAILUSER=xxx@gmail.com
PASSWORD=xxx@pass
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use dotenv to load environment variables from a folder root

about 4 years ago · Juan Pablo Isaza Report

0

your file should be named .env only in you project folder.

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!