defination on Node.js
npm i --save s-config
Examples
var picker = require('s-config');
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)
Parameters
id
String id of config for store or gettingdata
(String | Object) data or config source pathdata
(String | Object) data or config source path etc.
Examples
// 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');
Returns Object
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
Parameters
id
String id of config for store or gettingdata
(String | Object) data or config source pathdata
(String | Object) data or config source path etc.
Examples
// 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');
Returns Object
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.
Parameters
path
String suorce path (extension is required)
Examples
//
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') );
Returns Object js object from file