# cfg-watcher

> Simple config watcher. Can watch for files or kubernetes configmap changes.

Latest version **0.3.5** (published 2023-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install cfg-watcher
pnpm add cfg-watcher
yarn add cfg-watcher
bun add cfg-watcher
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2023-03-26 |
| First published | 2021-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 28.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | schaze |
| Maintainers | schaze |
| Keywords | kuberntes, watch, rxjs |

## Links

- npm: https://www.npmjs.com/package/cfg-watcher
- Repository: https://github.com/schaze/node-cfg-watcher
- Homepage: https://github.com/schaze/node-cfg-watcher#README.md
- npm.io page: https://npm.io/package/cfg-watcher

## Dependencies (7)

- [rxjs](https://npm.io/package/rxjs.md) ~7.4.0
- [winston](https://npm.io/package/winston.md) ~3.3.3
- [jsonschema](https://npm.io/package/jsonschema.md) ~1.4.0
- [watch-rx-ts](https://npm.io/package/watch-rx-ts.md) ~1.2.4
- [k8s-watch-rx](https://npm.io/package/k8s-watch-rx.md) ~0.3.4
- [fast-deep-equal](https://npm.io/package/fast-deep-equal.md) ~3.1.3
- [@kubernetes/client-node](https://npm.io/package/@kubernetes/client-node.md) ~0.14.0

## Recent versions

- 0.3.5 (latest) — 2023-03-26
- 0.3.4 — 2022-10-16
- 0.3.3 — 2022-01-02
- 0.3.1 — 2021-12-30

## README

# cfg-watcher

## About
Simple config watcher. 
Can watch changes on local files or kubernetes configmaps, handles input validation via JSON Schema and emits changes file contents.

## Basic usage example:

```typescript

import { join } from "path";
import { ConfigContentWatcher, ConfigFileWatcher, ConfigMapWatcher } from "cfg-watcher";

const cfgSchema = require?.main?.require('./cfgItems.JSONSchema.json');

const CFG_FOLDER='./cfg';
const CFG_CFGMAP_NAME='app-config';

const BACKEND = 'kubernetes';

const watcher = (BACKEND === 'file' ?
            new ConfigFileWatcher(['*.yaml', '*.yml'].map(fileFilter => join(CFG_FOLDER, fileFilter))) :
            new ConfigMapWatcher(CFG_CFGMAP_NAME));

const contentWatcher = new ConfigContentWatcher(
    watcher, 
    cfgSchema, 
    cfgItem => cfgItem.id); // provide a method to obtain cfg item id



contentWatcher.changes$.subscribe({
    next: change => {
        if (change.name === 'remove') {
            console.log('Removed cfg item: ', change.id);
        } else if (change.name === 'add') {
            console.log('Added cfg item: ', change.item.obj);
        } else if (change.name === 'update') {
            console.log('Updated cfg item: ',change.item.obj);
        }
    }
});

contentWatcher.onInit();


// on application close
contentWatcher.onDestroy();

```

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