@boundstate/env

Load and validate environment variables in node.js with TypeScript.

Usage no npm install needed!

<script type="module">
  import boundstateEnv from 'https://cdn.skypack.dev/@boundstate/env';
</script>

README

@boundstate/env

Load and validate environment variables in node.js with TypeScript.

$ npm install @boundstate/env joi@^17

Usage

import { EnvManager } from '@boundstate/env';
import * as Joi from '@hapi/joi';

interface Env {
  DATABASE_URL: string;
  DEBUG: boolean;
  PORT: string;
}

const env = new EnvManager<Env>({
  schema: {
    DATABASE_URL: Joi.string(),
    DEBUG: Joi.boolean().truthy('1').falsy('0').optional().default(false),
    PORT: Joi.string(),
  },
});

env.load({
  dotenvPath: __dirname + '/../.env',
});

console.log(env.get('DEBUG'));