0.0.9 • Published 3 years ago

nestjs-remote-firebase-config v0.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

NestJS-RemoteConfig

The RemoteConfig module could be used when you need to share config storage across all your microservices. You can use namespaces to separate config data.

  • Works with Firestore
  • Supports namespaces
  • Native NestJS support

Requirements!

Install via NPM:

$ npm i nestjs-remote-firebase-config

Export env variable

export GOOGLE_APPLICATION_CREDENTIALS=[path-to-your-key.json]

Import the package

import { EStoreType, RemoteConfigModule } from 'nestjs-remote-firebase-config';

Then you should register the package on the top level of the application

@Module({
    imports: [
        RemoteConfigModule.register({
          store: EStoreType.FIREBASE,
          opts: {}, // opts is not required. could be used instead of env var
        }),
    ],
})
export class AppModule {}

How to set up config variables

First of all, you should be familiar with Firebase firestore

Firestone docs!

Remote config package by default searches for the configuration collection to get all available configs (documents)

Example of config setup in firestore

ConfigExample

As soon as you change configuration collection documents they will be sync with you application

Receiving config value

@Injectable()
export class AppService {
    constructor(
        @Inject('RemoteConfigProviderToken')
        private readonly configService: FirebaseRemoteConfigService,
    )

    method() {
      const param = this.configService.getConfig<Number>('account', 'bonus_amount');
    } 
}