@jrosadob/ms-config
v0.0.27
Published
ms-config
Downloads
49
Maintainers
Readme
@jrosadob/ms-config
Package dependencies
This package use:
$ npm i cloud-config-client
$ npm i @nestjs/config
How use
Install
$ npm i @jrosadob/ms-config
Sample .env
file
The rest of the configuration should be on the configuration server in yml format.
# Endpoint Config Server (Mandatory)
ENDPOINT=http://localhost:8901
# Application name (Mandatory)
CONFIG=ms-auth
# Environment (Optional)
LABEL=development
Use in main.ts
This sample show how use ConfigServer in main.ts
import { NestFactory } from '@nestjs/core'
import { Logger } from '@nestjs/common'
import { ConfigService, LoadConfig } from '@jrosadob/ms-config'
import { AppModule } from './app.module'
async function bootstrap() {
const configService = await LoadConfig()
const environment = configService.get('NODE_ENV').toUpperCase()
const nameApp = configService.getServer('app.name')
const portTcp = +configService.getServer('app.portTcp')
const portHttp = +configService.getServer('app.portHttp')
const app = await NestFactory.create(AppModule)
await app.startAllMicroservices()
await app.listen(portHttp)
Logger.log(
`Microservice ${nameApp}: HTTP(s) Listening on http://localhost:${portHttp}`,
'Bootstrap',
)
Logger.log(`Environment: ${environment}`, 'Bootstrap')
}
bootstrap()
Use in app.module.ts
Only, if ConfigService is used in main.ts
import { Module } from '@nestjs/common'
import { ConfigService } from '@jrosadob/ms-config'
@Module({
imports: [],
controllers: [],
providers: [ConfigService],
})
export class AppModule {}
If not use ConfigService in main.ts, your app.modele.ts shoudlbe: