0

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
[email protected]
PASSWORD=xxx@pass
1
  • are you using some nestjs package to read & parse the .env? Commented Oct 29, 2021 at 0:38

2 Answers 2

0

Use dotenv to load environment variables from a folder root

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.