# dyna-config-handler

> Simplifies the configuration handling in json files for node-js applications

Latest version **1.0.4** (published 2018-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install dyna-config-handler
pnpm add dyna-config-handler
yarn add dyna-config-handler
bun add dyna-config-handler
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-02-13 |
| First published | 2017-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 40.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Anel dev |
| Maintainers | dennisat |

## Links

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

## Dependencies (1)

- [dyna-node-fs](https://npm.io/package/dyna-node-fs.md) ^0.1.4

## Recent versions

- 1.0.4 (latest) — 2018-02-13
- 1.0.3 — 2018-02-11
- 1.0.2 — 2017-10-08
- 1.0.1 — 2017-10-08
- 0.1.1 — 2017-10-08
- 0.0.4 — 2017-09-27
- 0.0.3 — 2017-09-27
- 0.0.2 — 2017-09-26

## README

# About

The `dyna-config-handler` simplifies the configuration handling in json files for node-js applications.

Written in Typescript, runs everywhere, universal and in non Typscript projects.  

# Usage

```
import {} from "";

interface IMyConfig {
	databaseName: string;
	bufferSize: number;
}

const ch = new DynaConfigHandler<IMyConfig>({
	filename: './myConfigFile.json',
	defaults: {
		databaseName: 'superChat-20',
		bufferSize: 2000000,
	},
});

ch.load()
.then(() => {
	// configuration is loaded
	ch.config.databaseName; // == 'superChat-20'
})
.catch((error: IError) => {
	// system error loading this file
});

// later in the code

ch.save(); // return promise

```

# Constructor, configuration of the `dyna-config-handler`

The constructor accepts one configuration object of this interface:
```
IConfiguration<C> {		// where C is your interface of your configuration
  filename?: string;
  defaults?: C;
  config?: C;
}
```

# Methods

## reset(): void

Set the configuration to `defaults` or to `{}` if defaults are not defined.

## save(humanReadable: boolean = true): Promise<void> 

Saves the configuration.

## load(): Promise<void>

Loads the configuration from the `filename` defined in the constructor.

You in the `IConfiguration` you defined `filename` you habe to call this in order to load the configuration.

Note: the `config` object is replaced with this.

## delete(): Promise<boolean>

Returns Promise boolean if the file is really deleted. It will return false if there is no file. In case of disk error the Promise.reject will be called _so catch it_.

# Properties

## config (shorthand `c`)

This is your configuration. You are free to change it. You can save it at any time you want. `dyna-config-handler` is not changing anything from it.

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