Hapiness Config
Configuration module based on node-config & js-yaml libraries.
Table of contents
Using config module
yarn
or npm
it in your package.json
$ npm install --save @hapiness/config
or
$ yarn add @hapiness/config
"dependencies": {
"@hapiness/core": "^1.0.0-beta.6",
"@hapiness/config": "^1.0.0-beta.6",
}
Standalone
./config/default.yml
:
my:
config: test
Node.js Script
:
import { Config } from '@hapiness/config';
Config.load();
if (Config.has('my.config')) {
console.log(Config.get('my.config'));
}
Hapiness
./config/default.yml
:
my:
baseUrl: 'test'
Hapiness module
:
import {
HapinessModule,
CoreModuleWithProviders,
InjectionToken,
Inject,
Optional,
} from '@hapiness/core';
const CONFIG = new InjectionToken('config');
interface Config {
baseUrl: string;
}
@HapinessModule({
...
})
export class ExternalModule {
static setConfig(config: Config): CoreModuleWithProviders {
return {
module: ExternalModule,
providers: [{ provide: CONFIG, useValue: config }]
};
}
}
export class Service {
constructor(@Optional() @Inject(CONFIG) config) {
...
}
}
import {
HapinessModule,
} from '@hapiness/core';
import { ExternalModule } from 'external-module';
import { Config } from '@hapiness/config';
Config.load();
@HapinessModule({
...
imports: [ ExternalModule.setConfig(Config.get('my')) ]
})
...
Back to top
Change History
- v1.0.0-beta.6 (2017-05-26)
- Latest packages versions
- Module version related to core version.
- v1.0.0-beta.5 (2017-05-15)
- Latest packages versions
- Module version related to core version.
- v1.0.0-beta.4 (2017-05-15)
- Latest packages versions
- Fix phony scripts
- Documentation.
- Module version related to core version.
- v1.0.0-beta.3 (2017-05-11)
- Create
Config
module. - Tests module.
- Documentation.
- Module version related to core version.
Back to top
Maintainers
Back to top
License
Copyright (c) 2017 Hapiness Licensed under the MIT license.
Back to top