No description
Find a file
2025-11-04 13:46:40 +01:00
.husky fix: Remove unused hook 2023-12-10 12:52:08 +01:00
src fix: Allow to return undefined 2023-12-10 13:18:19 +01:00
testing 🎉 Initial commit 2023-06-28 11:49:52 +02:00
.eslintrc.json feat: First try 2023-12-10 12:27:52 +01:00
.gitignore 🎉 Initial commit 2023-06-28 11:49:52 +02:00
.gitlab-ci.yml Fix: Gitlab ci yd 2023-12-10 12:33:02 +01:00
jest.config.cjs 🎉 Initial commit 2023-06-28 11:49:52 +02:00
nest-cli.json 🎉 Initial commit 2023-06-28 11:49:52 +02:00
package.json 0.0.6 2023-12-10 13:18:25 +01:00
pnpm-lock.yaml chore: Migrate to pnpm 2025-11-04 13:46:40 +01:00
README.md feat: Readme 2023-12-10 12:43:24 +01:00
tsconfig.build.json 🎉 Initial commit 2023-06-28 11:49:52 +02:00
tsconfig.json 🎉 Initial commit 2023-06-28 11:49:52 +02:00

Gettings started

Installing the package along with @nestjs/config:

pnpm install @nestjs/config @devdroplets/nestjs-easy-config

Create a class that defines your Config schema:

// src/app-config.ts
import { ConfigType } from '@devdroplets/nestjs-easy-config';
import { IsString, IsInt } from 'class-validator';

@ConfigType()
export class AppConfig {
  // Validate using class-validator!
  @IsInt()
  PORT: number;

  // Define defaults!
  @IsString()
  HOST = 'localhost';
}

Import the ConfigModule and register your schema:

// src/app.module.ts

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppConfig } from './app-config';

@Module({
  imports: [ConfigModule.forRoot(AppConfig)],
})
export class AppModule {}

Now in any service or controller, you can inject the config using your decorated config class:

// src/app.service.ts

import { Injectable } from '@nestjs/common';
import { AppConfig } from './app-config';

@Injectable()
export class AppService {
  constructor(private readonly config: AppConfig) {}

  getHello(): string {
    // Typed, validated and populated with defaults!
    return `Hello ${this.config.HOST}:${this.config.PORT}!`;
  }
}