# get-env-or-die

> Utility to get and typecast environment variables.

Latest version **1.0.18** (published 2022-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install get-env-or-die
pnpm add get-env-or-die
yarn add get-env-or-die
bun add get-env-or-die
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.18 |
| Published | 2022-01-10 |
| First published | 2021-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | hupe1980 |
| Keywords | env, environment-variables |

## Links

- npm: https://www.npmjs.com/package/get-env-or-die
- Repository: https://github.com/hupe1980/get-env-or-die
- Homepage: https://github.com/hupe1980/get-env-or-die#readme
- Issues: https://github.com/hupe1980/get-env-or-die/issues
- npm.io page: https://npm.io/package/get-env-or-die

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 1.0.18 (latest) — 2022-01-10
- 1.0.17 — 2022-01-03
- 1.0.16 — 2021-12-27
- 1.0.15 — 2021-12-20
- 1.0.14 — 2021-12-13
- 1.0.13 — 2021-12-06
- 1.0.12 — 2021-11-29
- 1.0.11 — 2021-11-22
- 1.0.10 — 2021-11-15
- 1.0.9 — 2021-11-08
- 1.0.8 — 2021-11-01
- 1.0.7 — 2021-10-25
- 1.0.6 — 2021-10-18
- 1.0.5 — 2021-10-11
- 1.0.4 — 2021-10-04
- … 16 more at https://npm.io/package/get-env-or-die/versions

## README

# get-env-or-die
![Build](https://github.com/hupe1980/get-env-or-die/workflows/build/badge.svg)
![Release](https://github.com/hupe1980/get-env-or-die/workflows/release/badge.svg)

> Utility to get and typecast environment variables.

## Installation

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

## How to use
### String environment variable
```typescript
import { getEnv } from 'get-env-or-die';
process.env.HOST = 'hostname';
const host = getEnv('HOST') // => 'hostname'
```

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

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

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

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

### Url environment variable
```typescript
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
```typescript
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
```typescript
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](LICENSE)

---
_Source: https://npm.io/package/get-env-or-die · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
