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:

const 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"
    );
  }
};