title: Get environment specific configuration from a JSON object using Lodash
body: <p>Given that I have the following JSON object,</p>
  
  <pre><code>dbConfig = {
      "db": "default",
      "default": {
          "defaultDB": "sqlite",
          "init": "init",
          "migrations": {
              "directory": "migrations",
              "tableName": "migrations"
          },
          "pool": {
              "min": "2",
              "max": "10"
          },
          "sqlite": {
              "client": "sqlite3",
              "connection": {
                  "filename": "data/default/sqlitedb/test.db"
              }
          },
          "oracle": {
              "client": "oracledb",
              "config": {
                  "development": {
                      "user": "test",
                      "pass": "test",
                      "db": "test"
                  },
                  "production": {
                      "user": "test",
                      "pass": "test",
                      "db": "test"
                  },
                  "test": {
                      "user": "test",
                      "pass": "test",
                      "db": "test"
                  }
              }
          }
      }
  };
  </code></pre>
  
  <p>Using Node &amp; <a href="https://lodash.com" rel="nofollow">Lodash</a>, is there any possibility of getting either <code>connection</code> or <code>config.</code> depending on what <code>dbConfig.default[dbConfig.default.defaultDB]</code> is set to. </p>
  
  <p>So for instance if i set <code>dbConfig.default.defaultDB=oracledb</code> and <code>process.env.NODE_ENV=development</code> I want to be able to get <code>dbConfig.default[dbConfig.default.defaultDB].config.development</code></p>
  
  <p>Or if I set <code>dbConfig.default.defaultDB=sqlite</code> just to get <code>dbConfig.default[dbConfig.default.defaultDB].connection</code></p>
  
  <p>In other words, if the database has environment specific configuration then this will be in <code>"config": {}</code> and if not in <code>"connection": {}</code></p>
  
  <p>It doesn't have to be Lodash. It can also be plain javascript.</p>