Use direct `process.env` access and standardized configuration management instead of custom environment variable wrappers. Avoid redundant abstraction layers when the framework or libraries already handle environment variable inference automatically.
Use direct process.env access and standardized configuration management instead of custom environment variable wrappers. Avoid redundant abstraction layers when the framework or libraries already handle environment variable inference automatically.
Key principles:
process.env.VARIABLE_NAME instead of custom env objects when possible@t3-oss/env-nextjs package for environment variable validation and type safetyENABLED_XXX for feature flags and XXX_API_KEY for API keyssrc/config/app.ts)AUTH_XXX variables)Example:
// โ Avoid custom wrappers when direct access works
clientId: authEnv.AUTH_GOOGLE_CLIENT_ID ?? process.env.AUTH_GOOGLE_CLIENT_ID
// โ
Use direct access for new implementations
clientId: process.env.AUTH_GOOGLE_CLIENT_ID
// โ
Use @t3-oss/env-nextjs for validation
import { createEnv } from '@t3-oss/env-nextjs';
export const appEnv = createEnv({
server: {
ENABLED_CLOUDFLARE: z.boolean().default(false),
CLOUDFLARE_API_KEY: z.string().optional(),
}
});
This approach reduces complexity, improves maintainability, and leverages existing framework capabilities for environment variable management.
Enter the URL of a public GitHub repository