2

When i set my username and password directly in a nodemailer server, it works as expected

auth: {
    user: 'myusername',
    pass: 'mypassword'
},

But on using dotenv, nothing happens

require ('dotenv').config();

auth: {
  user: process.env.USERNAME,
  pass: process.env.PASSWORD
},

I ran npm install dotenv on server side and set up a .env file with the variables below:

USERNAME:myusername

PASSWORD:mypassword

3 Answers 3

5

As noted in the dotenv docs, it expects the variables in the format NAME=VALUE. Your file should instead contain:

USERNAME=myusername
PASSWORD=mypassword
Sign up to request clarification or add additional context in comments.

1 Comment

thank you. but it still isn't working after the changes
4

The syntax in your .env file is incorrect. Use equals = signs rather than colon :.

USERNAME=myusername
PASSWORD=mypassword

See also: https://www.npmjs.com/package/dotenv

Comments

1

i was having the same problem when i had the name of env file as .env.local but when i changed the name of the file to simple .env , it worked!

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.