Options
All
  • Public
  • Public/Protected
  • All
Menu

Typenv Documentation

typenv

Codecov npm (tag) GitHub Workflow Status

Typenv intends to provide .env configuration with type safety in mind.

Installation

Using yarn

yarn add typenv

Using npm

npm i typenv

Usage

Documentation

Quick Start

.env

DB_HOST=192.168.1.1
DB_PORT=1234

src/database_config.ts

import { load, loadSync, Key } from "typenv";

class DatabaseConfig {
  @Key("DB_HOST", "localhost")
  public hostname: string;

  @Key("DB_PORT", 5432)
  public port: number;
}

const config = await load(DatabaseConfig);
// or
const config = loadSync(DatabaseConfig);

console.log(config.hostname);
// > "192.168.1.1"
console.log(config.port);
// > 1234

Configuration

Environment variables

  • DOTENV_CONFIG_PATH - Location of .env file (defaults to $CWD)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Generated using TypeDoc