@ryan/nestjs-easy-config (0.0.6)
Published 2025-11-04 14:21:13 +00:00 by Ryan
Installation
@ryan:registry=npm install @ryan/nestjs-easy-config@0.0.6"@ryan/nestjs-easy-config": "0.0.6"About this package
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}!`;
}
}
Dependencies
Development dependencies
| ID | Version |
|---|---|
| @nestjs/common | ^9.2.1 |
| @nestjs/core | ^9.2.1 |
| @nestjs/testing | ^9.2.1 |
| @types/jest | ^29.2.4 |
| @typescript-eslint/eslint-plugin | >=5.43.0 |
| @typescript-eslint/parser | >=5.43.0 |
| class-validator | ^0.14.0 |
| eslint | >=8.0.0 |
| graphql | ^16.6.0 |
| husky | ^8.0.0 |
| jest | ^29.3.1 |
| lodash | ^4.17.21 |
| reflect-metadata | ^0.1.14 |
| ts-jest | ^29.0.3 |
| ts-morph | ^17.0.1 |
| typescript | >=4.4 |
Peer dependencies
| ID | Version |
|---|---|
| @nestjs/common | >=9 || ^8.2.3 |
| @nestjs/config | >=2 |
| @nestjs/core | >=9 || ^8.2.3 |
| class-transformer | * |
| class-validator | * |
| reflect-metadata | ^0.1.13 |
Details
2025-11-04 14:21:13 +00:00
Assets (1)
Versions (1)
View all
npm
11
Ryan Saebu
MIT
latest
2.6 KiB
nestjs-easy-config-0.0.6.tgz
2.6 KiB
0.0.6
2025-11-04