@chaoyangnz/app-config
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

App config service for Angular and NestJS

Install

npm i @cloudaffine/app-config

Angular

In your AppModule

import { ConfigModule } from '@cloudaffine/app-config/angular';
import { APP_INITIALIZER } from '@angular/core';

@NgModule({
    imports: [
        ConfigModule.forRoot({
            browser: {
                url: '/config.json'
            },
            server: {
                paths: ['./config.yaml']
            }
        })
    ],
    providers: [
        {
            provide: APP_INITIALIZER
            useFactory: ConfigModule.initializer,
            multi: true
        }
    ]
})
export class AppModule {}

Then in your service or component, optional you can specify a type as the config schema.

@Injectable()
export class SomeService {
    constructor(private configService: ConfigService<any>) {}

    func() {
        const aa = this.configService.config.aa;
    }
}

NestJS

In your AppModule

imort { ConfigModule } from '@cloudaffine/app-config/nestjs';

@Module({
    imports: [
        ConfigModule.forRoot({
            paths: ['./config.yaml']
        })
    ]
})
export class AppModule {}

Then in your service or component, optional you can specify a type as the config schema.

@Injectable()
export class SomeService {
    constructor(private configService: ConfigService<any>) {}

    func() {
        const aa = this.configService.config.aa;
    }
}

Package Sidebar

Install

npm i @chaoyangnz/app-config

Weekly Downloads

1

Version

0.3.3

License

MIT

Unpacked Size

74.6 kB

Total Files

45

Last publish

Collaborators

  • chaoyangnz