Skip to content

feat: add environment configuration validation using zod and dotenv#9

Merged
Kmario19 merged 2 commits intomainfrom
feat/validate-environment-variables
Apr 3, 2025
Merged

feat: add environment configuration validation using zod and dotenv#9
Kmario19 merged 2 commits intomainfrom
feat/validate-environment-variables

Conversation

@Kmario19
Copy link
Copy Markdown
Owner

@Kmario19 Kmario19 commented Apr 3, 2025

This pull request introduces significant updates to the environment configuration and initialization process. The changes mainly focus on validating environment variables using the zod library and improving the structure of the environment loading process.

Environment configuration and validation:

  • src/config/environment.ts: Added a new module that uses zod to validate environment variables and ensure they have the correct types and default values. This module also loads the environment variables using dotenv.

Initialization process improvements:

  • src/index.ts: Removed the direct use of dotenv and replaced it with the new loadEnvironment function from the environment configuration module. This change ensures environment variables are validated before being used.
  • src/index.ts: Moved the PORT variable assignment inside the conditional block that checks if the environment is not 'test', ensuring the server only starts in non-test environments.

@Kmario19 Kmario19 requested a review from Copilot April 3, 2025 03:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces environment variable validation using the zod library, streamlining the configuration initialization process. Key changes include:

  • Introducing a new module (src/config/environment.ts) that validates environment variables using zod and dotenv.
  • Refactoring src/index.ts to remove direct dotenv usage and employ the loadEnvironment function for validation.
  • Moving the PORT assignment into the conditional block to ensure the server only starts outside of test environments.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/index.ts Replaces dotenv usage with loadEnvironment and adjusts PORT assignment.
src/config/environment.ts Implements environment variable validation using zod, throwing errors when invalid.

Comment thread src/config/environment.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Kmario19 Kmario19 merged commit ab9e820 into main Apr 3, 2025
1 check passed
@Kmario19 Kmario19 deleted the feat/validate-environment-variables branch April 3, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants