Configuration Management

Learn how to define configurations

Introduction

Configurations define property values used by the application to configure its behavior.

All configurations are located in app/configs directory. Environment-specific configurations (e.g., NODE_ENV=production) must reside in the env subdirectory and named after the target environment (e.g., app/configs/env/production). Environment-specific configurations overwrite the values in general-purpose configuration files.

Defining a Configuration

Define a configuration by exporting an object from the configuration file.

app/configs/facebook.js
module.exports = {
  api_key: 'api key goes here'
};

Accessing the Configuration

You access the configuration by looking it using the blueprint.lookup() method. Because application configuration are the first resource loaded, it is safe to lookup a configuration at any time within in the servers lifetime. For example, the code snippet below shows how to access the Facebook API key from the configuration above:..

app/controllers/facebook.js
const {Controller} = require ('@onhilltech/blueprint');

module.exports = Controller.extend ({
  apiKey: null,
  
  init () {
    this._super.call (this, ...arguments);
    const config = this.app.lookup ('config:facebook');
    this.apiKey = config.apiKey;
  }
});

Last updated