MasterController

Configuration

Environments, server settings, and services.

MasterController reads per-environment settings and lets you register injectable services, so the same codebase behaves correctly in development, test, and production.

Environments#

Set the active environment with NODE_ENV (or the master env var) and read per-environment config from config/environments/env.<env>.json.

config/environments/env.development.json
{
  "server": { "httpPort": 3001, "hostname": "127.0.0.1", "requestTimeout": 30000 }
}

Dependency injection#

Register services with different lifetimes and inject them where needed:

MethodLifetime
master.addTransient(name, fn)New instance every resolution.
master.addScoped(name, fn)One instance per request.
master.addSingleton(name, fn)One instance for the app’s lifetime.
javascript
master.addSingleton('mailer', () => new Mailer(process.env.SMTP_URL));
master.addScoped('currentUser', (ctx) => resolveUser(ctx));

Extending controllers & views#

Share helpers across all controllers or the view layer:

javascript
master.extendController(SharedHelpers);
master.useView(MyViewAdapter);
The init file
Component and app initializers (config/initializers/config.js) are the conventional place to register middleware, services, CORS, and view engines — they run once at startup.