configjs-loader

A simple script that loads json files into a config object for use in an app.


Keywords
configuration, config, native, web, app
License
LGPL-3.0
Install
npm install configjs-loader@1.0.3

Documentation

Version License Author

ConfigJS Loader

A simple config loader, that loads JSON files and returns an object of the loaded files and their contents.

Installation

It's a simple NPM package, so just run a normal NPM installation

npm i configjs-loader

Usage

See the test script below for example usage. All you need to supply as an argument is the directory that contains the config files. The script will attempt to recurse over that directory, finding all JSON files, and attempting to parse them. Returns a promise that must be awaited, which then returns the object of the configs loaded.

Configuration files are loaded into an object based on their filename. For example, if you have 2 config files, one.json and two.json, their properties will be loaded into {}.one and {}.two, respectively.

'use strict';
const configLoader = require("configjs-loader");
const path = require("path");

(async ()=>{
  const conf = await configLoader(path.join(__dirname, "configs"));
  console.log(conf);
})();