AvnerCohen / file-conf-cache

A simple node module that allows reading a local file (configuration file) and updating in-memory store in the case of file change.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File Conf Cache

Build status

A simple node js module that allows treating a local file as a configuration database.

This is done by making sure that every property read will efficiently check if the file is updated, if it is, the repository will be updated.

Usage:

var fileConfCache = require('file-conf-cache');

// Init configuration:
const conf = fileConfCache('configuration.json')
//
Define a reader method:

function readerMethod(_, key){
    return _[key];
}

//read data
conf.getValue(readerMethod, 'somevalue')
Reader method

Reader method is left for the client to implment to allow functionalities such as default value:

function readerMethod (_, key, defaultValue){
  return _[key] || defaultValue;
}

conf.getValue(readerMethod, 'non-existing', 'marak') == 'marak'

Or various other more complicated logic

About

A simple node module that allows reading a local file (configuration file) and updating in-memory store in the case of file change.

License:MIT License


Languages

Language:JavaScript 100.0%