Search code examples
node.jsenvironment-variablesdotenv

How can I use an env variable as a key in a object?


I have the following code. I want to set the xxxxxx in logins to process.env.cognitoId, where congitoId has the string I need to pass in as a key. This particular string is unique and must not be shown, how can I achieve this?

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  IdentityPoolId: process.env.IdentityPoolId,
  Logins: {
    'xxxxxxxxx': val.token
  }
})

Solution

  • Use [] not string interpolation. That will allow you to set the key