1

So I'm trying to think of a solution to select specific npm's env variables for instance:

process.env.LOCATIONS_HOST
 or 
process.env.SOME_OTHER_API_HOST

Then I can write a function to get that like

getSpecificHost(name) {
 return process.env.name
}

Thanks!

RyGuy
  • 23
  • 4
  • 2
    You can use `process.env[name]` where name is a string. – Dan D. Aug 26 '19 at 21:24
  • Hmm I thought I tried that but it didn't work I'll give it another shot thans @dan – RyGuy Aug 26 '19 at 21:29
  • Possible duplicate of [Dynamically access object property using variable](https://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable) – laggingreflex Aug 26 '19 at 22:59
  • @DanD. that doesnt work for me, its undefined. I created a post regarding this issue. Maybe you can help out. – beeftony Nov 09 '21 at 10:51
  • @beeftony Are you sure that the environment variable is actually set? Is it included in the output of `env`? – Dan D. Nov 10 '21 at 03:02
  • Yes, process.env['MIX_VARIABLE_NAME'] works process.env[variable] where variable = 'MIX_VARIABLE_NAME' doesnt. – beeftony Nov 10 '21 at 12:16

0 Answers0