Skip to content

6.4 quick start

wiki[bot] edited this page Aug 23, 2026 · 1 revision

6.4. Quick Start

Installation

npm install @triplef/config-factory
npm install @triplef/helpers @nestjs/common joi

Basic Setup

1. Create a ConfigService

import { Injectable } from '@nestjs/common';
import { CacheReturnValue } from '@triplef/config-factory/cache-return-value';
import Joi from 'joi';

const AppConfigSchema = Joi.object({
  port: Joi.number().port().default(3000),
  host: Joi.string().hostname().default('localhost'),
  env: Joi.string().valid('development', 'production', 'test').default('development'),
});

@Injectable()
export class AppConfigService {
  @CacheReturnValue(AppConfigSchema)
  get config() {
    return {
      port: parseInt(process.env.PORT || '3000'),
      host: process.env.HOST || 'localhost',
      env: process.env.NODE_ENV || 'development',
    };
  }
}

2. Register with ConfigFactoryModule

import { Module } from '@nestjs/common';
import { ConfigFactoryModule } from '@triplef/config-factory/config-factory';
import { AppConfigService } from './app-config.service';

@Module({
  imports: [
    ConfigFactoryModule.forRoot({
      global: true,
      providers: [AppConfigService],
    }),
  ],
})
export class AppModule {}

Import Paths

The library is tree-shakeable. Import only what you need:

import { CacheReturnValue } from '@triplef/config-factory/cache-return-value';
import { ConfigFactoryModule } from '@triplef/config-factory/config-factory';
import { ValidateReturnValue, ValidateReturnValueError } from '@triplef/config-factory/validate-return-value';

Clone this wiki locally