all InfoSec news
Typed ConfigService in NestJS
Jan. 4, 2024, 2:24 p.m. | Taehyuk Han
DEV Community dev.to
Preview
- Strongly Typed argument(property path) for Nested Configuration Object
- Dynamic return type according to config variables
Introduction
In NestJS, ConfigModule with ConfigService helps store and load configuration variables in .env file for convenience instead of using process.env.
Using the standard constructor injection, loading the variables with ConfigService would be like:
// config/configuration.ts
export default () => ({
port: parseInt(process.env.PORT, 10) || 3000,
database: {
host: process.env.DATABASE_HOST || 'localhost',
port: parseInt(process.env.DATABASE_PORT, 10) || 5432
}
});
// app.module.ts
@Module({
imports: [ …
argument configuration convenience default dynamic env export file injection introduction nested nestjs object path preview process property return standard store
More from dev.to / DEV Community
Jobs in InfoSec / Cybersecurity
CyberSOC Technical Lead
@ Integrity360 | Sandyford, Dublin, Ireland
Cyber Security Strategy Consultant
@ Capco | New York City
Cyber Security Senior Consultant
@ Capco | Chicago, IL
Senior Security Researcher - Linux MacOS EDR (Cortex)
@ Palo Alto Networks | Tel Aviv-Yafo, Israel
Sr. Manager, NetSec GTM Programs
@ Palo Alto Networks | Santa Clara, CA, United States
SOC Analyst I
@ Fortress Security Risk Management | Cleveland, OH, United States