defination on Node.js
npm i --save s-config
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)
(String)
id of config for store or getting
Object
:
// 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');
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
(String)
id of config for store or getting
Object
:
// 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');
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.
(String)
suorce path (extension is required)
Object
:
js object from file
//
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') );