简体   繁体   中英

Unable to get environment variable with node-config in Window (self answer)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM