# rob-config

> Robust configuration package for nodejs, built on top of convict

Latest version **6.0.0** (published 2020-04-18) · MIT license · 0 weekly downloads

## Install

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

Provides the command `rob-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 | 6.0.0 |
| Published | 2020-04-18 |
| First published | 2016-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.18.1 |
| Dependencies | 5 |
| Unpacked size | 148.8 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | Jérôme Macias |
| Maintainers | jeromemacias |
| Keywords | config, configuration, schema, validation, robust |

## Links

- npm: https://www.npmjs.com/package/rob-config
- Repository: https://github.com/jeromemacias/node-rob-config
- Homepage: https://github.com/jeromemacias/node-rob-config#readme
- Issues: https://github.com/jeromemacias/node-rob-config/issues
- npm.io page: https://npm.io/package/rob-config

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ~4.0.0
- [yargs](https://npm.io/package/yargs.md) ~15.3.1
- [convict](https://npm.io/package/convict.md) ~5.2.0
- [yargonaut](https://npm.io/package/yargonaut.md) ~1.1.4
- [prettyjson](https://npm.io/package/prettyjson.md) ~1.2.1

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 6.0.0 (latest) — 2020-04-18
- 4.2.0 — 2018-12-16
- 4.1.1 — 2018-07-26
- 4.1.0 — 2018-03-04
- 4.0.0 — 2018-01-28
- 3.1.0 — 2018-01-27
- 3.0.0 — 2018-01-27
- 2.0.0 — 2017-11-13
- 1.0.0 — 2017-01-10
- 0.1.0 — 2016-12-22

## README

# rob-config

[![NPM version](http://img.shields.io/npm/v/rob-config.svg)](https://www.npmjs.org/package/rob-config)
![node-current](https://img.shields.io/node/v/rob-config)
[![Build Status](https://travis-ci.org/jeromemacias/node-rob-config.svg?branch=master)](https://travis-ci.org/jeromemacias/node-rob-config)

Robust configuration module for nodejs, built on top of [`convict`](https://github.com/mozilla/node-convict).

## Installation

`npm install rob-config --save`

## Why another config package?

[`config`](https://github.com/lorenwest/node-config) is a very simple and powerfull config package but it lacks from schema and validation.

[`convict`](https://github.com/mozilla/node-convict) is not simple to use, but way more robust and overridable.

So I wanted something:

-   Easy to use like `config`
-   With schema and documentation like `convict`
-   With possibility to override with env variable or command line argument like `convict`
-   With a command to validate config for dev AND before deployment to production
-   With a command to see the builded config depends on env and default value (easier to debug)

Here it is and it's very easy to migrate from `config` or `convict`.

## Usage

Define a config schema, simple object.

See https://github.com/mozilla/node-convict#the-schema for documentation about schema definition.

For example: `config/schema.js`

```js
module.exports = {
    env: {
        doc: 'The applicaton environment.',
        format: ['production', 'staging', 'integration', 'development', 'test'],
        default: 'development',
        env: 'NODE_ENV',
    },
    api: {
        port: {
            doc: 'The API port',
            format: 'port',
            default: 3000,
        },
        timeout: {
            doc: 'The API timeout',
            format: 'nat',
            default: 60 * 1000, // 1 minutes
        },
    },
};
```

Then, define the first config file.

For example: `config/development.js`

```js
module.exports = {
    api: {
        port: 3001, // test with "nothing" value to see validation error
    },
};
```

You can, optionnaly, define a `config/formats.js` to add one or more custom format to convict.

See https://github.com/mozilla/node-convict#custom-format-checking for documentation about custom formats.

`convict.addFormats()` will be call under the hood.

For exemple: `config/formats.js`

```js
module.exports = {
    'float-percent': {
        validate: function (val) {
            if (val !== 0 && (!val || val > 1 || val < 0)) {
                throw new Error('must be a float between 0 and 1, inclusive');
            }
        },
        coerce: function (val) {
            return parseFloat(val, 10);
        },
    },
};
```

### Display your builded configuration

Run `./node_modules/.bin/rob-config show`:

![Display final configuration](example/screenshot/show.png?raw=true)

### Validate your configuration against schema

Run `./node_modules/.bin/rob-config validate`:

![Validate configuration ok](example/screenshot/validate-ok.png?raw=true)

In case of error:

![Validate configuration error](example/screenshot/validate-error.png?raw=true)

### Display the schema description

Run `./node_modules/.bin/rob-config describe`:

![Schema description](example/screenshot/describe.png?raw=true)

### Use it in your project

```js
const config = require('rob-config');

console.log(config.get('api.port'));
```

### Change config dir

You can set env variable `ROB_CONFIG_DIR` with the relative path of your project configuration directory.

## Versioning

To keep better organization of releases we follow the [Semantic Versioning 2.0.0](http://semver.org/) guidelines.

See [Releases](https://github.com/jeromemacias/node-rob-config/releases) for detailed changelog.

## License

[MIT License](/LICENSE) © [Jérôme Macias](https://github.com/jeromemacias)

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