I'm unable to use node-config to get environment variables in Windows.
My index.js is running a CMD with nodemon.
I've open a new CMD and typed set myApp_jwtSecretKey=mySecretHere
// config/custom-environment-variables.json
{
"jwtSecretKey": "myApp_jwtSecretKey"
}
// index.js
console.log(config.get('myApp_jwtSecretKey'))
// I would expect to see 'mySecretHere' but I get an empty string instead
Why is that?
Hi myself from the past!
The reason you are not getting what you'd expect has to do with the set
command of Windows.
Using set
the variable is limited to the current command line session.
You need to use setx
to set variables permanently and so those can share between command line sessions.
In your case, within your CMD, type setx myApp_jwtSecretKey mySecretHere