0

Comparatively new to JS and node,

Requirement: Need to set the environment variables after reading it from a secure store before the config module is loaded.

Details: We have an ask where we need to read the secrets from a secret store and make it available to the node environment before the config module kicks in and assigns values using the default.js.

I tried splitting the express app setup and initialization and tried reading the secrets in between those steps, but to no avail.

app.js -> Setup the app

index.js -> 
// Setup the environments with the secrets
import config from 'config'
import {app_init} from './app' // Setting up the express app

// Now setting up the env variables
process.env.DB_HOST = 'MyDbHost'
process.env.DB_PASS = 'DBPass' // This will be read from the secret store

log.info(`DB_HOST used in ENV: ${process.env.DB_HOST}`) // Prints the right value
log.info(`DB_HOST used in config: ${config.database.host}`) // Prints undefined

Anyway, Is there a way to inject the secrets in the env before the config module reads them?

Please let me know if you need more info.

RookieDev
  • 241
  • 3
  • 7
  • 18

1 Answers1

0

Looking at the config documentation, especially here one can use either deferred configuration and use full nodejs capabilities to create the configuration.


In my case, i am planning to read the secrets from the store and published them as the environment variables. I will publish if I see challenges doing that.

RookieDev
  • 241
  • 3
  • 7
  • 18