Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

environment variables not working in node js server

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

like image 952
mahnuel Avatar asked Aug 11 '26 16:08

mahnuel


1 Answers

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

USERNAME=myusername
PASSWORD=mypassword
like image 119
awarrier99 Avatar answered Aug 13 '26 08:08

awarrier99



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!