env-files-loader
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

deno-env-loader

Type safe .env loader written in deno

Usage

.env

PORT=8080
HOST=localhost
NODE_ENV=development
DEBUG=true

src/env.ts

import {loader, $number, $string, $enum, $boolean, $env} from 'https://raw.githubusercontent.com/ppdx999/deno-env-loader/main/mod.ts'

export type Env = Infer<typeof env>;
export const [env, errors] = loader(
  Deno.readTextFileSync("./.env"),
  $env({
    PORT: $number,
    HOST: $string,
    NODE_ENV: $enum(["development", "production"]),
    DEBUG: $boolean,
  }),
);

if (errors !== null) {
  throw new Error(`failed to validate env: ${errors.join(", ")}`);
}

Readme

Keywords

none

Package Sidebar

Install

npm i env-files-loader

Weekly Downloads

10

Version

0.1.0

License

MIT

Unpacked Size

12.9 kB

Total Files

21

Last publish

Collaborators

  • ppdx999