1.1.0 • Published 1 year ago

env-assert v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

env-assert

Setup (after install):

npx env-assert
yarn env-assert
pnpm env-assert

This will create an example config file

env-assert.config.ts

Here you can setup your required and optional environment variables

import type { CreateEnvVarsType } from "env-assert";

const required = ["FOO"] as const;
const optional = ["BAR"] as const;

const config = {
  required,
  optional,
};

export default config;

export type EnvVars = CreateEnvVarsType<typeof config>;

How to use

Run env-assert before any script, for example:

yarn env-assert && yarn build

CleanShot 2022-11-27 at 8 28 20

Pass the type of your config to CreateEnvVarsType to receive a type that you can use to extend ProcessEnv, so you know what variables are available. 👌 CleanShot 2022-11-27 at 8 23 12

global.d.ts

import { EnvVars } from "./env-assert.config";

export declare global { declare namespace NodeJS { interface ProcessEnv extends EnvVars {} } }