0

Sometimes I don't have access to app let's say in my Database Pool singleton and I need a way to detect the environment while instantiating pools and other resources etc, retrieve development or production configs.

I tried to lookup process object and process.env but couldn't find much.

Wondering if there's another way to detect the environment, I came across passing variables when running app.js but it's not possible in the production environment, so any other suggestions please.

or as a last resort, I'll add a variable to process.env object in a cautious manner.

user2727195
  • 7,122
  • 17
  • 70
  • 118
  • Take a look at http://stackoverflow.com/questions/4870328/how-to-read-environment-variable-in-node-js – Nat May 28 '15 at 04:34
  • I believe `process.env.ENV_VARIABLE` requires me to set variable to each environment where code runs on, that's what I wanna avoid – user2727195 May 28 '15 at 04:35
  • my current workaround is setting `process.app = app` and then accessing it in modules where `app` is not available – user2727195 May 28 '15 at 04:38
  • You can simply declare a global variable in that case. Otherwise, take a look at Dependency Injection approach http://nerdventure.io/fount-dependency-injection-for-node-js/ – Nat May 28 '15 at 04:42
  • thanks. used `GLOBAL.env = app.get('env')` – user2727195 May 28 '15 at 05:13

0 Answers0