# confi

> a simple configuration library

Latest version **10.0.1** (published 2021-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install confi
pnpm add confi
yarn add confi
bun add confi
```

## 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 | 10.0.1 |
| Published | 2021-02-19 |
| First published | 2011-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | First+Third |
| Maintainers | jga, dawnerd, ecwillis, orthagonal1, alaguna, aleperez92 |
| Keywords | config, settings, env |

## Links

- npm: https://www.npmjs.com/package/confi
- Repository: https://github.com/firstandthird/confi
- Issues: https://github.com/firstandthird/confi/issues
- npm.io page: https://npm.io/package/confi

## Dependencies (6)

- [aug](https://npm.io/package/aug.md) ^3.0.1
- [varson](https://npm.io/package/varson.md) ^2.1.0
- [envload](https://npm.io/package/envload.md) ^0.1.0
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.13.1
- [parse-dir](https://npm.io/package/parse-dir.md) ^4.0.1
- [confi-helpers](https://npm.io/package/confi-helpers.md) 1.0.0

## 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

- 10.0.1 (latest) — 2021-02-19
- 10.0.0 — 2020-11-06
- 9.10.1 — 2019-06-10
- 9.10.0 — 2019-05-28
- 9.9.0 — 2019-05-08
- 9.8.0 — 2018-11-12
- 9.7.0 — 2018-10-30
- 9.6.0 — 2018-10-11
- 9.5.0 — 2018-08-25
- 9.4.0 — 2018-08-20
- 9.3.0 — 2018-08-17
- 9.2.3 — 2018-05-09
- 9.2.2 — 2018-05-09
- 9.2.1 — 2018-03-24
- 9.2.0 — 2018-03-21
- … 51 more at https://npm.io/package/confi/versions

## README

<h1 align="center">Confi</h1>

<p align="center">
  <a href="https://github.com/firstandthird/confi/actions">
    <img src="https://img.shields.io/github/workflow/status/firstandthird/confi/Test/main?label=Tests&style=for-the-badge" alt="Test Status"/>
  </a>
  <a href="https://github.com/firstandthird/confi/actions">
    <img src="https://img.shields.io/github/workflow/status/firstandthird/confi/Lint/main?label=Lint&style=for-the-badge" alt="Lint Status"/>
  </a>
</p>

Confi loads configuration data from yaml, json or from a `package.json` with support for `NODE_ENV` overrides.


## Installation

```sh
npm install confi
```

_or_

```sh
yarn add confi
```


## Usage

_Note: `confi()` is an async method._

_Note: Default configuration directory is `./conf/`_

Configuration files that start with `default` are loaded and merged together. This allows you to split up configuration logic into smaller files.

You can create a file that matches `NODE_ENV` which will apply it's values on top of anything set in default. This allows you to create configuration for production and development environments.

User specific configuration can be created as well by placing config files in a `users` directory inside of the config directory.

__`./conf/default.yaml`__
```yaml
title: 'Example Site'
site:
  name: '{{ title }} - DEV'
updateEvery: '{{ ms("1h") }}
appId: '{{ getEnv("APP_ID", '09830948029384') }}'
shot: false
```

__`./conf/users/han.json`__
```json
{
  "shot": true
}
```

__`./conf/production.yaml`__
```yaml
site:
  name: '{{ title }}'
updateEvery: '{{ getEnv("UPDATE_EVERY", ms("1h")) }}'
```

__Basic__
```javascript
const confi = require('confi');

async function startApp() {
  const config = await confi();

  console.log(config.site.name); // Example Site - DEV
  console.log(config.appId); // 09830948029384
  console.log(config.updateEvery); // 3600000
  console.log(config.shot); // false
}

startApp();
```

__User__
```javascript
const confi = require('confi');

async function startApp() {
  const config = await confi({
    user: 'han'
  });

  console.log(config.site.name); // Example Site - DEV
  console.log(config.appId); // 09830948029384
  console.log(config.updateEvery); // 3600000
  console.log(config.shot); // true
}

startApp();
```

__Environment__
```javascript
// imagine process.env.UPDATE_EVERY is 10000
const confi = require('confi');

async function startApp() {
  const config = await confi({
    env: 'production'
  });

  console.log(config.site.name); // Example Site
  console.log(config.appId); // 09830948029384
  console.log(config.updateEvery); // 10000
  console.log(config.shot); // true
}

startApp();
```

For more examples, see the test directory.


## Options

### `confi([options])`

  - `path` - Supply an alternate path to load config from. Default: `process.env.CONFI_PATH` or `./conf`
  - `env` - Manually set the envitonment. Default: `dev`
  - `userPath` - Path for user overrides. Default: `./conf/users`
  - `context` - Advanced option to pass additional information to `varson` for parsing configs.
  - `helpers` - Additional helper methods to expose.
  - `user` - Which user shall the user config be loaded for.


# Helpers

Confi comes with a set of helper methods. You can find [documentation for them here](https://github.com/firstandthird/confi-helpers).

---

<a href="https://firstandthird.com"><img src="https://firstandthird.com/_static/ui/images/safari-pinned-tab-62813db097.svg" height="32" width="32" align="right"></a>

_A [First + Third](https://firstandthird.com) Project_

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