@uandev/env
v2.0.0
Published
A handy wrapper for building configurations with environment variables
Downloads
4
Readme
UANDEV Environment Variable Wrapper
A handy wrapper for building configurations out of environment variables.
Usage
This module works best with TypeScript. It provides the following:
EnvString
Load an environment variable of the given name and treat it as a string
EnvNumber
Load an environment variable of the given name and treat it as a number
EnvBoolean
Load an environment variable of the given name and treat it as a boolean
EnvArrayString
Load an environment variable of the given name and treat it as an array of strings
Example
I prefer using this within my project configuration module. So it usually goes like this:
import { LoadArrayString, LoadBoolean, LoadNumber, LoadString } from '@uandev/env'
export module Config {
export const Postgres = {
host: LoadString('PG_HOST'),
port: LoadNumber('PG_PORT', 5432),
ssl: LoadBoolean('PG_SSL', true),
database: LoadString('PG_DATABASE'),
user: LoadString('PG_USER'),
password: LoadString('PG_PASSWORD')
}
export const ThingForArrayDemo = LoadArrayString('ARRAY_THING', ',')
}
ConnectToPostgres(Config.Postgres)
console.log(Config.ThingForArrayDemo)