Wednesday, 17 March 2021

Can't access process.env values using dynamic keys

I have a nextjs (not sure if it has any relevance or does it apply to nodejs as a whole) project in which I would like to access a value from process.env using a dynamic key:

const myKey = 'MY_KEY'
console.log(process.env[myKey]) //undefined

For reference, I have tried:

console.log(process.env['MY_KEY']) // gives value under MY_KEY
console.log(process.env.MY_KEY) // works too


from Can't access process.env values using dynamic keys

No comments:

Post a Comment