nestjs-configuration
Environment variables validation and ConfigModule setup.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
NestJS Configuration Standards
Priority: P1 (OPERATIONAL)
Environment configuration and validation patterns for NestJS applications.
Setup
-
Library: Use
@nestjs/config. -
Initialization: Import
ConfigModule.forRoot({ isGlobal: true })inAppModule.
Validation
- Mandatory: Validate environment variables at startup.
-
Tool: Use
joior a custom validation class. -
Effect: The app must crash immediately if a required env var (e.g.,
DB_URL) is missing.
// app.module.ts
ConfigModule.forRoot({
validationSchema: Joi.object({
NODE_ENV: Joi.string()
.valid('development', 'production')
.default('development'),
PORT: Joi.number().default(3000),
DATABASE_URL: Joi.string().required(),
}),
});
Usage
-
Injection: Inject
ConfigServiceto access values. - Typing: Avoid magic strings. Use a type-safe getter helper or a dedicated configuration object/interface.
-
Secrets: Never commit
.envfiles. Add.env*to.gitignore.
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!