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

1.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i typenv

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

33.3 kB

Total Files

31

Last publish

Collaborators

  • maarvin