@nwx/cfg
A simple configuration module for Angular applications

Overview
@nwx/cfg attempts to streamline the app configuration while keeping it DRY.
How to install
npm i @nwx/cfg <|OR|> yarn add @nwx/cfg
How to use
import { AppCfg, TargetPlatform, HttpMethod } from '@nwx/cfg';
export const environment: AppCfg = {
appName: 'Neekware',
target: TargetPlatform.web,
production: true
};
import { CfgModule } from '@nwx/cfg';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, CfgModule.forRoot(environment)],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Component } from '@angular/core';
import { CfgService } from '@nwx/cfg';
@Component({
selector: 'app-root'
})
export class AppComponent {
title = '@nwx/cfg';
constructor(public cfg: CfgService) {
this.title = this.cfg.options.appName;
}
}
Advanced usage:
@nwx/cfg
can also be used to fetch remote configuration prior to start of an Angular app.
import { AppCfg, TargetPlatform, HttpMethod } from '@nwx/cfg';
export const environment: AppCfg = {
appName: 'Neekware',
target: TargetPlatform.web,
production: true,
rmtCfg: {
endpoint: '/api/cfg',
method: HttpMethod.get,
timeout: 3,
headers: { 'Content-Type': 'application/json' }
body: {
}
}
};
import { CfgModule } from '@nwx/cfg';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, CfgModule.forRoot(environment)],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Component } from '@angular/core';
import { CfgService } from '@nwx/cfg';
@Component({
selector: 'app-root'
})
export class AppComponent {
title = '@nwx/cfg';
options = {};
constructor(public cfg: CfgService) {
this.options = {
...this.cfg.options,
...{ name: 'AppComponent' }
};
const remoteCfgData = this.options.rmtData;
}
}
Running the tests
To run the tests against the current environment:
npm run ci
License
Released under a (MIT) license.
Version
X.Y.Z Version
`MAJOR` version -- making incompatible API changes
`MINOR` version -- adding functionality in a backwards-compatible manner
`PATCH` version -- making backwards-compatible bug fixes