JLannoo / env-checker

An npm package for checking your environment variables based on a schema. Can be used along with Zod.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Environment Variables Checker

Description

It's a simple script to check if the environment variables are set and correspond to the expected values or types.

The types and/or values of the environment variables are defined in a schema. You can use it along Zod for validations or just with a Vanilla JS Object.

Usage

First, you need to initialize the checker with the schema and the environment variables.

npx env-var-check init

Or, if you want to use it with Zod:

npx env-var-check init --zod

This will generate a /env folder containing a schema.mjs file and a env.d.ts file to use with Typescript. (You will need to include the /env folder in your tsconfig.json file)

Then, you can run the checker:

npx env-var-check check 

Or your schema is using Zod:

npx env-var-check check --zod

You might want to add it to package.json and do something like this to check the environment variables before running the app:

{
  "scripts": {
    "predev": "env-var-check check",
    "prestart": "env-var-check check",
    "dev": "...",
    "start": "..."
  }
}

Options

init

  • --zod: Initialize the schema with Zod objects instead of Vanilla JS Objects

check

  • --zod: Use Zod to validate the environment variables
  • --env: Specify the path to the environment variables file (default: .env)
  • --schema: Specify the path to the schema file (default: ./env/schema.mjs)

TODO

  • Add tests
  • Add more options
  • Implement the --schema option to specify a custom schema file path
  • Add more examples

About

An npm package for checking your environment variables based on a schema. Can be used along with Zod.


Languages

Language:TypeScript 80.2%Language:JavaScript 19.8%