exports

defination on Node.js

npm i --save s-config

exports
Example
var picker = require('s-config');

picker

Make a map of configs. s-config can read and store configurations constants. To read a file or object and set it in a constant, pass the name (id) of the constant to the 'picker'( require('s-config') ) and the arguments to the list of objects or paths to the files. After thath, you can get the constant in any part of app from 'picker'( require('s-config') ) by constant name(id)

picker(id: String, data: (String | Object), data: (String | Object)): Object
Parameters
id (String) id of config for store or getting
data ((String | Object)) data or config source path
data ((String | Object)) data or config source path etc.
Returns
Object:
Example
// set constant from file
var config = require('s-config')('config-id', './path/to/source/config.json');

// set constant after reading and merge data of files and objects
var config = require('s-config')('config-id-2', './test.json', {some: 'test2'}, './test.env');

extend

S-config assumes that the variable is a constant. In this connection, it blocks the ability to rewrite its value after installation. If you need to partially change or expand the constant, use the extension method

extend(id: String, data: (String | Object), data: (String | Object)): Object
Parameters
id (String) id of config for store or getting
data ((String | Object)) data or config source path
data ((String | Object)) data or config source path etc.
Returns
Object:
Example
// set constant from file
var config = require('s-config')('config-id', './path/to/source/config.json');
// extend or overide existing constatnt
var extendet = require('s-config').extend('config-id', './test.json', {some: 'test2'}, './test.env');

read

s-config can read .json and .env files. If you do not need to use constants, you can read the files without saving them inside of the s-config. Important - this method does not use ability to merge configuration.

read
Parameters
path (String) suorce path (extension is required)
Returns
Object: js object from file
Example
//
require('s-config').read('./test.env');
require('s-config').read('./test.json');

// Emulation of the "dotenv" approach
// read of environment variable from '.env' and write it in process
Object.assign(process.env, require('s-config').read('.env') );
// expand of environment variable from environment file
Object.assign(process.env, require('s-config').read('./config/env/'+process.env.NODE_ENV+'.env') );