0

I am working on a nodejs app, I want to perform some action when environment variable is set to '1' and different action when environment variable is set to '0'.

I manually change the value of this variable from '0' to '1'. I still value '0' being printed. It didn't recognize the value change. Is there any better to read value from registry?

Note: I use process.env.variable_name

Here is the code snippet

function setVar () {
    if(process.env.Env_Variable_test) { 
        console.log('It is set!'); 
        console.log(process.env.Env_Variable_test);
    }
    else { 
        console.log('No set!'); 
        console.log(process.env.Env_Variable_test);
    }
}

enter image description here

karansys
  • 2,449
  • 7
  • 40
  • 78
  • 2
    As per my knowledge, when the nodejs process starts process.env will be loaded and if you want to change the env variable you will have to restart the process. – Prashanth S. Mar 11 '20 at 10:49
  • Thanks I see that , I have to exit the process then restart the process once again – karansys Mar 11 '20 at 10:53
  • Are there any better way to read the registry value – karansys Mar 11 '20 at 10:53
  • 1
    Not sure, check out this https://stackoverflow.com/questions/51446149/how-to-update-env-variables-in-a-process-without-restarting-it-nodejs/51446308 – Prashanth S. Mar 11 '20 at 11:02

0 Answers0