Nodejs environment variables

i am using windows 10 and poweshell. i created config dir and custom-environment-variables.json file and wrote all Mosh did. But there is an error that password is not defined.

this is an error that i see ?

what can i do ?

Hey its Harvel, I can help but could you send a screen shot of your default.json file where you added the mail property, also your custom environment variable file where you are referencing it to the environment variables

Well you didn’t show any code snippet for examining, that’s why am asking for the screen shot
Send em then I will help you

1 Like

this is my developer.json file

1 Like


this is my custom-environment-variables.json file

i could not change the environment variable using set NODE_ENV=production. it is not returning error but if i check the result ( console.log(process.env.NODE_ENV) ) development is on the console.

1 Like

Your configuration is at fault,
You are mapping a mail password property that doesn’t exist in your development. Json file.
I other ward password is not defined as a mail property

So add the password property after your host property in the mail object of your development. Json file.
Then you can refence it in your custom environment variable file

And about the NODE ENV, try closing all your terminal windows and set it again.
Set it inside your current working directory

Please :slight_smile:

could you show me some exaples you do!

i added password property to the development but how cen i refert to the global variable from this file

this is what i see on the console if i wantto console the password
image

Oh dear, you are missing something
Try this below :slight_smile:

Set mail in as below in different files :

In development. Json as

" mail" :{
“host” :“host example”,
“password” : "mailPassword "
}

Then In custom environment Variable file as

“mail” :{
“password” :“mailPassword”
}

Then you will have to set a value to that “mailPassword” in the console window ie

Set mailPassword=any value here on windows

Incase of any enlighten that you could perhaps need, reach me on WhatsApp @
+256705296862

You should also be aware of a couple of issues with Windows dev. If using VSCode, playing with Environmental Variables on the fly seems to require a restart of VSCode to pick up changes. VSCode does allow us to quick re-load the application, so the best I’ve found so far is closing VSCode and right clicking the project folder and opening with VSCode

Semi-related - nodemon doesn’t work with latest versions of Win10/11 Nodemon not working in windows · Issue #2088 · remy/nodemon · GitHub

Oops hello, my apologies for the delayed response

I did try to show you some code on the forum, little did I know that you heard sent me an email,
Am wondering whether you did solve the pro

@Harvel - Not yet unfortunately. And when we’re switching often between say “test” and “production” environments, its super frustrating. Hoping some other CI/CD tools may get around this issue, but I’m not at that stage yet

Do you have a git hub account?