1.0.1 • Published 2 years ago
types-from-env v1.0.1
What is it?
types-from-env is a cli utility which reads a dotenv file, and generates a ts file with the keys in the dotenv file exported as a const EnvVarNames
and a type EnvVarKey
.
Installation
yarn add types-from-env --dev
npm install --save-dev types-from-env
Usage
types-from-env <path-to-dotenv-file> <path-to-output-ts-file>
Sample
Input
NODE_ENV=default
APP_SERVER_HOST=localhost
APP_SERVER_PORT=
DB_HOST=
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_MIN_CONNECTIONS=2
DB_MAX_CONNECTIONS=10
Output
/**
* This is an autogenerated file.
* Please do not change the types by hand here.
* They will be overwritten.
*
* File generated by types-from-env
*/
export const EnvVarNames = [
'NODE_ENV',
'APP_SERVER_HOST',
'APP_SERVER_PORT',
'DB_HOST',
'DB_USER',
'DB_PASSWORD',
'DB_NAME',
'DB_MIN_CONNECTIONS',
'DB_MAX_CONNECTIONS',
] as const;
export type EnvVarKey = typeof EnvVarNames[number];
And that's pretty much it!
Author: Balaganesh Damodaran (asleepysamurai@gmail.com) License: MIT