const environment = process.env.ENVIRONMENT || 'development' import config from '../knexfile'; export default function get_knex() { if (!Object.keys(config).includes(environment)) { throw "No Knex database configuration was found for environment '" + environment + "'. Please check your configuration."; } var _knex = undefined; console.log("Using Knex config: ", config[environment]) try { _knex = require('knex')(config[environment]); } catch (e) { throw [ "Failed to initialize Knex database connection with config: " + JSON.stringify(config[environment]), e ]; } return _knex; }