1.0.18 • Published 2 years ago

get-env-or-die v1.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

get-env-or-die

Build Release

Utility to get and typecast environment variables.

Installation

npm install --save get-env-or-die

How to use

String environment variable

import { getEnv } from 'get-env-or-die';
process.env.HOST = 'hostname';
const host = getEnv('HOST') // => 'hostname'

Optional Fallback

import { getEnv } from 'get-env-or-die';
const host = getEnv('HOST', 'localhost') // => 'localhost'

Int environment variable

import { getIntEnv } from 'get-env-or-die';
process.env.PORT = '80';
const port = getIntEnv('PORT', 8080) // => 80

Boolean environment variable

import { getBoolEnv } from 'get-env-or-die';
process.env.DEBUG = '1';
const isDebug = getBoolEnv('DEBUG', false) // => true

String array environment variable

import { getArrayEnv } from 'get-env-or-die';
process.env.KEYWORDS = 'a,b,c';
const keywords = getArrayEnv('KEYWORDS') // => ['a','b','c']

Url environment variable

import { getUrlEnv } from 'get-env-or-die';
process.env.URL = 'http://example.com';
const url = getUrlEnv('URL') // => new URL('http://example.com')

Date environment variable

import { getDateEnv } from 'get-env-or-die';
process.env.DATE = '2020-11-11';
const date = getDateEnv('DATE') // => new Date('2020-11-11')

RegExp environment variable

import { getRegExpEnv } from 'get-env-or-die';
process.env.REG_EXP = '/ab+c/i';
const regExp = getRegExpEnv('REG_EXP') // => new RegExp('ab+c', 'i')

Errors

All functions throw an error if the environment variable is not convertible or the env is missing and no fallback is provided.

License

MIT

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.9

3 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago