@abinnovision/nestjs-configx
Type-safe configuration for NestJS using Standard Schema.
Installation
yarn add @abinnovision/nestjs-configx
Goals
- Type-safe configuration from
process.env - Schema-agnostic via Standard Schema (Zod, ArkType, etc.)
- Minimal NestJS integration (just a provider, no module)
- Fail-fast validation at startup
Non-goals
- Multiple config sources (at least not yet)
- Async schema validation
- Runtime config reloading
- Secret management / encryption
Quick Start
1. Define your config
import { configx } from "@abinnovision/nestjs-configx";
import { z } from "zod";
export class AppConfigx extends configx(
z.object({
PORT: z.string().default("3000").transform(Number),
HOST: z.string().default("0.0.0.0"),
}),
) {}
2. Register as provider
import { Module } from "@nestjs/common";
import { AppConfigx } from "./app.configx";
@Module({
providers: [AppConfigx],
exports: [AppConfigx],
})
export class AppModule {}
3. Inject and use
@Injectable()
export class AppService {
constructor(private readonly config: AppConfigx) {}
getPort() {
return this.config.PORT; // number - fully typed
}
}
Schema Libraries
Any Standard Schema compatible library works. Tested with:
ArkType Example
import { configx } from "@abinnovision/nestjs-configx";
import { type } from "arktype";
export class AppConfigx extends configx(
type({
PORT: "string.numeric.parse = '3000'",
HOST: "string = '0.0.0.0'",
}),
) {}
Error Handling
Invalid configuration throws InvalidConfigError at instantiation with details about which fields failed validation.
License
Apache-2.0