Typenv intends to provide .env configuration with type safety in mind.
Using yarn
yarn add typenv
Using npm
npm i typenv
.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
Environment variables
DOTENV_CONFIG_PATH
- Location of.env
file (defaults to$CWD
)
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.