# config-settings

> Reading configuration from json file or consul.

Latest version **2.3.1** (published 2021-02-01) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.3.1 |
| Published | 2021-02-01 |
| First published | 2018-09-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 63.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | yunnysunny |
| Maintainers | yunnysunny |
| Keywords | config, setting |

## Links

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

## Dependencies (2)

- [consul](https://npm.io/package/consul.md) ^0.39.0
- [node-slogger](https://npm.io/package/node-slogger.md) ^2.0.0

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

- 2.3.1 (latest) — 2021-02-01
- 3.2.0 (beta) — 2021-04-14
- 3.1.0 — 2021-04-14
- 3.0.0 — 2021-04-12
- 2.3.0 — 2021-01-29
- 2.2.0 — 2021-01-28
- 2.1.0 — 2020-12-08
- 2.0.3 — 2020-12-01
- 2.0.2 — 2020-11-30
- 2.0.1 — 2020-11-30
- 2.0.0 — 2020-11-30
- 1.0.0 — 2020-04-08
- 0.2.2 — 2020-01-13
- 0.2.1 — 2018-09-12
- 0.2.0 — 2018-09-11
- … 1 more at https://npm.io/package/config-settings/versions

## README

# config-setttings

[![build status][travis-image]][travis-url]
[![David deps][david-image]][david-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![node version][node-image]][node-url]

[npm-url]: https://npmjs.org/package/config-settings
[travis-image]: https://img.shields.io/travis/yunnysunny/config-settings.svg?style=flat-square
[travis-url]: https://travis-ci.org/yunnysunny/config-settings
[coveralls-image]: https://img.shields.io/coveralls/yunnysunny/config-settings.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/yunnysunny/config-settings?branch=master
[david-image]: https://img.shields.io/david/yunnysunny/config-settings.svg?style=flat-square
[david-url]: https://david-dm.org/yunnysunny/config-settings
[node-image]: https://img.shields.io/badge/node.js-%3E=_6-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/

[![NPM](https://nodei.co/npm/config-settings.png?downloads=true)](https://nodei.co/npm/node-config-settings/)  

## install

npm install config-settings --save

## Usage
### Use with JsonConfig
```json
{
    "var":"xxxx",
    "integer":111,
    "dir":"/var/xxx",
    "dirNotExist":"1234567890qwerty",
    "file":"/var/filename",
    "fileDirExist":"/var/filenotexist",
    "fileNotExist":"098987655oiouyuyt",
    "int":11,
    "notInt":"xx",
    "url":"http://baidu.com"
}
```

```javascript
const config = require('../config.json');
const {JsonConfig} = require('config-settings');
const jsonConfig = new JsonConfig(config);
var varstr = jsonConfig.loadNecessaryVar('var');//get xxxx
var integer = jsonConfig.loadNecessaryVar('integer');//get 111

```

### Use with ConsulConfig

```javascript
const {ConsulConfig} = require('config-settings');
const settings = new ConsulConfig({consulAddr:'127.0.0.1:8500'});

settings.loadNecessaryVar('var').then(function(value) {
    const varstr =  value;
});
settings.loadNecessaryVar('integer').then(function(value) {
    const integer =  value;
});
settings.allLoaded().then(function() {
    //all loading progress finished
}).catch(function() {

});
```

### Use the ConsulSyncConfig

```javascript
const {ConsulSyncConfig} = require('config-settings');
const settings = new ConsulConfig({consulAddr:'127.0.0.1:8500', keys: ['var', 'integer']});

const varstr =  settings.loadNecessaryVar('var');
const integer =  settings.loadNecessaryVar('integer');
```

**Attention**

When call the function start with `loadNecessary` failed, the module will throw Error in asynchronous way.

## API

See the document of [api](doc/api.md)


## Test

You should set the environment variable of `CONSUL_SERVER` in format of `ip:port` before `npm run`.

## License

[MIT](LICENSE)

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