EggJS provides the feature of configuration at project level. EggBornJS extends the feature provided by EggJS, realizing the configuration at the module level

  1. Module can specify its own configuration
  2. The configuration at project level can override the one at module level

Definition of Config

src/module/test-party/backend/src/config/config.js

module.exports = appInfo => {
  const config = {};

  config.message = 'Hello World';

  return config;
};

Usage of Config

Same Module

src/module/test-party/backend/src/controller/kitchen-sink/guide.js

async echo2() {
  const message = this.ctx.config.message;
  this.ctx.success(message);
}

Across Module

async echo2() {
  const message = this.ctx.config.module('test-party').message;
  this.ctx.success(message);
}
Name Description
config.module(moduleName) get the config of the specified module

Override Config

Use project level config to override module level config, thereby changing Hello World to Hello World!

src/backend/config/config.default.js

// modules
config.modules = {
  'test-party': {
    message: 'Hello World!',
  },
};

Because EggJS can specify config separately for test environment, development environment and production environment, we can also customize the config of modules for different environments