Skip to content

Add environment-specific configuration template #60

@PAMulligan

Description

@PAMulligan

Description

Add an environment configuration utility to the generated project templates. This provides type-safe environment variable loading with validation, replacing raw `process.env` access.

Why

Raw `process.env` access is untyped and error-prone — missing variables cause runtime crashes. A typed config utility catches missing/invalid variables at startup with clear error messages.

Acceptance Criteria

  • Add a `src/config.ts` template to `setup-project.sh`

  • Use Zod for environment variable validation:
    ```typescript
    import { z } from 'zod';

    const envSchema = z.object({
    NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
    PORT: z.coerce.number().default(3000),
    DATABASE_URL: z.string().url(),
    JWT_SECRET: z.string().min(32),
    LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
    });

    export const config = envSchema.parse(process.env);
    export type Config = z.infer;
    ```

  • Import and use `config` in the generated `src/index.ts` instead of raw `process.env`

  • Provide different defaults for development vs. production

  • For Cloudflare Workers, adapt to use Hono's `Bindings` pattern instead

  • CI passes

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions