Stop Hardcoding: Start with a Config Layer
Every app needs configuration. API keys, database URLs, feature flags, ports. The lazy way is to sprinkle process.env calls directly in your business logic. That works until you need to test, share config across services, or change a value without redeploying. The clean way is to centralize config into a single, typed, validated module.
The Problem with Raw process.env
Raw environment variables are strings, untyped, and often missing. If you access process.env.PORT and it's undefined, you get a runtime crash later, not a clear error at startup. Also, you can't easily provide defaults or validate that required keys exist. And when you have 20 variables, your code becomes a mess of process.env.SOMETHING scattered everywhere.
The Clean Pattern: Config Module






