# config-env2

> A tiny lib to validate env file at runtime

Latest version **0.0.1** (published 2021-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install config-env2
pnpm add config-env2
yarn add config-env2
bun add config-env2
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2021-05-07 |
| First published | 2021-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 17 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | cbyad |
| Maintainers | cbyad |

## Links

- npm: https://www.npmjs.com/package/config-env2
- Repository: https://github.com/cbyad/config-env2
- Issues: https://github.com/cbyad/config-env2/issues
- npm.io page: https://npm.io/package/config-env2

## Dependencies (3)

- [nconf](https://npm.io/package/nconf.md) ^0.11.2
- [tslib](https://npm.io/package/tslib.md) ^2.2.0
- [dotenv](https://npm.io/package/dotenv.md) ^8.1.0

## Recent versions

- 0.0.1 (latest) — 2021-05-07

## README

# CONFIG-ENV2 (WIP)
## About
`config-env2` stands for config en**V**ironment **V**alidator. A tiny library to validate environment variables at runtime and extract content.

It's backed by [fp-ts](https://github.com/gcanti/fp-ts) for functional prog utilities and [io-ts](https://github.com/gcanti/io-ts) for runtime validation and define custom types.
For those who are unfamiliar with functional programming **No Worries** you need to only import `npm i io-ts` and follow `example` supplied

## Usage
- Basic usage => `npm i io-ts config-env2`
- FP usage => `npm i io-ts fp-ts config-env2` 

## Example
1. Define your environment schema

```ts
import * as io from "io-ts"
import { NonEmptyString, NumberString, URL } from 'config-env2'

const MyEnvironment = io.strict({
    SQL_SERVER: NonEmptyString,
    SQL_DATABASE: NonEmptyString,
    SQL_USER: NonEmptyString,
    SQL_PASSWORD: NonEmptyString,
    SQL_CONNECTION_TIMEOUT: NumberString,
    SQL_REQUEST_TIMEOUT: NumberString,
    APP_HOST: URL
})
type MyEnvironment = io.TypeOf<typeof MyEnvironment>
```

2. validate and extract content
```ts
import { load } from "config-env2"
import { MyEnvironment } from "./src/environment"

const myConf = load(MyEnvironment)
const { SQL_SERVER: server, SQL_DATABASE: database, SQL_PASSWORD: password } = myConf

type SqlConf = {
    server: string
    database: string
    password: string
}
const connect = (_: SqlConf) => console.log("connected")

const sqlConf: SqlConf = { server, database, password }
connect(sqlConf)
```
If your env file is located in other place => `load(MyEnvironment,customPath)`

## Contribution
__TODO__

## License
The MIT License (MIT)

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