@uandev/env
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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)

Readme

Keywords

none

Package Sidebar

Install

npm i @uandev/env

Weekly Downloads

7

Version

2.0.0

License

MIT

Unpacked Size

12.2 kB

Total Files

11

Last publish

Collaborators

  • driverjb