# convar

> Get configuration value via default, config, environment variable, package, npm or cli with optional required error handling

Latest version **1.1.7** (published 2015-05-10) · MIT license · 0 weekly downloads

## Install

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

## 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.1.7 |
| Published | 2015-05-10 |
| First published | 2015-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | yieme |
| Maintainers | yieme |
| Keywords | config, env, environment, cli, package, default, envar |

## Links

- npm: https://www.npmjs.com/package/convar
- Repository: https://github.com/yieme/convar
- Issues: https://github.com/yieme/jsonit/issues
- npm.io page: https://npm.io/package/convar

## Dependencies (4)

- [envar](https://npm.io/package/envar.md) ^1.0.0
- [jsonic](https://npm.io/package/jsonic.md) ^0.1.1
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [packpath](https://npm.io/package/packpath.md) ^0.1.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

- 1.1.7 (latest) — 2015-05-10
- 1.1.6 — 2015-04-12
- 1.1.5 — 2015-04-12
- 1.1.4 — 2015-02-14
- 1.1.3 — 2015-02-14
- 1.1.2 — 2015-02-05
- 1.1.1 — 2015-01-17
- 1.1.0 — 2015-01-16
- 1.0.1 — 2015-01-16
- 1.0.0 — 2015-01-16

## README

# CONVAR

Get configuration variable via config file, environment variable, package, npm or cli with optional required error handling

## Install

```js
npm install convar --save
```

## Use

```js
var convar = require('convar')
  , token  = convar('token') // e27d9f2a29b7
```

Required values pass in error message or Error

```js
var convar = require('convar')
  , token  = convar('token', 'Missing access token') // e27d9f2a29b7
  , url    = convar('url',   new Error('Missing URL'))
```


### Value via command line

```sh
node app.js --token e27d9f2a29b7 --node_env dev
```

### Conditional flags

```sh
node app.js --debug
```

```app.js``` :

```js
var convar = require('convar')
  , debug  = convar('debug') // true
```

### Value via environment variable

```sh
token=e27d9f2a29b7
node_dev=dev

node app.js
```

### Ignore case

This will also work

```sh
TOKEN=e27d9f2a29b7
NODE_ENV=dev
```

### Value via JSON config

```sh
config='{ "token":"e27d9f2a29b7", "NODE_ENV":"dev" }'
```

### Value via [JSONIC](http://github.com/rjrodger/jsonic) simplified JSON

```sh
config=token:e27d9f2a29b7,NODE_ENV:dev
```

### JSON or [JSONIC](http://github.com/rjrodger/jsonic) variables

```sh
node app.js --config token:e27d9f2a29b7,NODE_ENV:dev --firebase url:https://example.firebaseio.com,token:e27d9f2a29b7e27d9f2a29b7
```

```js
var convar = require('convar')
  , token  = convar('token')        // e27d9f2a29b7
  , fbUrl  = convar('firebase').url // example.firebaseio.com
```

### JSON config file

```config.json``` file:

```js
{
  "token": "e27d9f2a29b7",
  "NODE_ENV": "dev",
  "firebase": {
    "url":   "https://example.firebaseio.com",
    "token": "e27d9f2a29b7e27d9f2a29b7"
  }
}
```

```config``` parameter is a file if it isn't JSON or [JSONIC](http://github.com/rjrodger/jsonic) and a string that contains ```.json```

```sh
node app.js --config config.json
```

## Prefixed values

Example with ```yo_``` prefix

```sh
node app.js --yo_token e27d9f2a29b7
```

Use

```js
var convar = require('convar')
convar.prefix('yo_')
var token  = convar('token')        // e27d9f2a29b7
```

## Package values

```js
var convar = require('convar')
console.log(convar.package.version) // 1.0.0
```

## License: MIT

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