Use consistent patterns for environment variable handling and configuration validation. Access environment variables directly where they’re needed rather than loading them unnecessarily in build configurations. Provide clear fallback mechanisms and fail fast with descriptive error messages when required configuration is missing or invalid.
Key practices:
process.env
directly in the consuming module instead of loading environment variables in build/config filesZERO_SCHEMA_PATH=shared/schema.ts
over hard-coding pathsconst loadSchemaJson = () => {
if (process.env.ZERO_SCHEMA_JSON) {
return process.env.ZERO_SCHEMA_JSON;
}
try {
const schema = readFileSync("zero-schema.json", "utf8");
return JSON.stringify(JSON.parse(schema));
} catch (error) {
throw new Error(
"Schema must be provided via ZERO_SCHEMA_JSON env var or zero-schema.json file"
);
}
};
.env.example
files for documentationEnter the URL of a public GitHub repository