npm

type-dotenv
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.6 • Public • Published

type-dotenv

An extremely simple typed dotenv loader.

Usage

import { join } from 'path';
import { config, load, IsBoolean, IsString, IsNumber } from 'type-dotenv';

class Environment {
  @IsString()
  NODE_ENV!: string;

  @IsNumber()
  PORT: number = 1337;

  @IsString()
  URL: string = 'http://localhost:1337';

  @IsBoolean()
  ENABLE_PLAYGROUND: boolean = false;

  // by default, everything is required
  @IsString({ required: false })
  ANALYTICS_KEY?: string;
}

// Same opts as `dotenv` package.
config({
  path: join(process.cwd(), '.env.development')
});

export const env = load(Environment);

console.log(env instanceof Environment) // true

Readme

Keywords

none

Package Sidebar

Install

npm i type-dotenv

Weekly Downloads

4

Version

1.0.0-beta.6

License

MIT

Unpacked Size

14.8 kB

Total Files

9

Last publish

Collaborators

  • jrdn