# Environment और Configuration — नेस्टजेएस

Source: https://www.geekswithgeeks.com/hi/nestjs/nestjs-env-config

> Environment variables और per-environment configuration को manage करें।

## ConfigModule setup

`.env` files को automatically load और validate करने के लिए `@nestjs/config` का उपयोग करें।

```typescript
import { ConfigModule } from '@nestjs/config';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: '.env'
    })
  ]
})
export class AppModule {}
```

## Config को access और validate करें

Values पढ़ने के लिए `ConfigService` को inject करें; schema validation के लिए Joi का उपयोग करें।

```typescript
import { ConfigService } from '@nestjs/config';

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

  getPort() {
    return this.config.get<number>('PORT') || 3000;
  }
}
```
