# cnm-config

> A package aiming at improving the loading of environment variables

Latest version **1.3.3** (published 2020-09-25) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2020-09-25 |
| First published | 2020-04-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jules Faucherre |
| Maintainers | jfaucherre |

## Links

- npm: https://www.npmjs.com/package/cnm-config
- npm.io page: https://npm.io/package/cnm-config

## Dependencies (2)

- [joi](https://npm.io/package/joi.md) ^17.2.1
- [ramda](https://npm.io/package/ramda.md) ^0.27.1

## Recent versions

- 1.3.3 (latest) — 2020-09-25
- 1.3.2 — 2020-09-25
- 1.3.1 — 2020-09-23
- 1.3.0 — 2020-09-13
- 1.2.5 — 2020-09-12
- 1.2.4 — 2020-09-12
- 1.2.3 — 2020-09-12
- 1.2.2 — 2020-04-05
- 1.2.1 — 2020-04-05
- 1.1.0 — 2020-04-04
- 1.0.0 — 2020-04-02

## README

# CNM-config

This repository is there to load configuration variables from your environment
and that check for required variables or sets default values etc.
It exports a function to which you can give an array of all the variables needed

### Usage

```
const load = require('cnm-config');

const config = [{
  name: 'PORT',
  'default': 8080,
  type: 'int',
}, {
  as: 'env',
  name: 'NODE_ENV',
  'default': 'development',
}, {
  as: 'connection',
  name: 'DB_CONNECTION',
  required: true,
}, {
  as: 'prodSecret',
  name: 'PROD_SECRET',
  required: ({ env }) => env === 'production',
}]

const { connection, env, prodSecret, PORT } = load(config);

// Do things with your config variables
```

### Detail

A variable description can have several options :
 - name (string, required) : the name of the environment variable
 - as (string) : the name the variable will have in the resulting object
 - required (boolean | function) : whether the variable is required or not, you can give it a function taking in argument the values of the resulting object and returning a boolean
 - default (any) : a default value if the variable is not defined and not required
 - type ('bool' | 'boolean' | 'int' | 'number' | 'integer' | 'list') : the type of the variable
 - description (string) : a description of what the variable do to be used as documentation

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