# json-evn-configurator

> Creates object with fields that are merged from environmental variables and fields from json file

Latest version **1.0.6** (published 2018-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-evn-configurator
pnpm add json-evn-configurator
yarn add json-evn-configurator
bun add json-evn-configurator
```

## 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.0.6 |
| Published | 2018-02-26 |
| First published | 2017-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | itrambovetskyi |
| Maintainers | itrambovetskyi |
| Keywords | config, json, env |

## Links

- npm: https://www.npmjs.com/package/json-evn-configurator
- Repository: https://github.com/itrambovetskyi/json-evn-configurator
- Homepage: https://github.com/itrambovetskyi/json-evn-configurator#readme
- Issues: https://github.com/itrambovetskyi/json-evn-configurator/issues
- npm.io page: https://npm.io/package/json-evn-configurator

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.6 (latest) — 2018-02-26
- 1.0.5 — 2018-01-26
- 1.0.4 — 2018-01-17
- 1.0.3 — 2018-01-17
- 1.0.2 — 2018-01-17
- 1.0.1 — 2017-12-14
- 1.0.0 — 2017-12-13

## README

# json-evn-configurator
Creates JS object with fields that are merged from environmental variables and fields from json file

## Usage example
1) Create config.json file with some configuration fields:
```json
{
  "CONFIGURATION_FIELD_1": "some config data",
  "CONFIGURATION_FIELD_2": "another config data"
}
```
2) Pass the path to the config.json file to the json-env-configurator:
```js
const configurator = require(`json-env-configurator`);
const config = configurator(pathToJsonFile);

console.log(config.CONFIGURATION_FIELD_1); // -> some config data
console.log(config.CONFIGURATION_FIELD_2); // -> another config data
```

3) If you specify environmental variable with the same name as in config.json file, environmental variable will has higher priority:

        CONFIGURATION_FIELD_2=overridden node app.js
        
app.js:
```js
const configurator = require(`json-env-configurator`);
const config = configurator(pathToJsonFile);

console.log(config.CONFIGURATION_FIELD_1); // -> some config data
console.log(config.CONFIGURATION_FIELD_2); // -> overridden
```

4) You can specify special prefix for environmental variables to separate configuration by environmental variables with namespaces

Let's create another configuration file - config2.json:

```json
{
  "HOST": "localhost",
  "PORT": "3000"
}
```

        FIRST_CONFIG.CONFIGURATION_FIELD_2=overridden SECOND_CONFIG.PORT=8080 node app.js

app.js:        
```js
const configurator = require(`json-env-configurator`);
const firstConfig = configurator(pathToFirstJsonFile, `FIRST_CONFIG`);
const secondConfig = configurator(pathToSecondJsonFile, `SECOND_CONFIG`);

console.log(firstConfig.CONFIGURATION_FIELD_1); // -> some config data
console.log(firstConfig.CONFIGURATION_FIELD_2); // -> overridden

console.log(secondConfig.HOST); // -> localhost
console.log(secondConfig.PORT); // -> 8080
```

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