1.1.0 • Published 5 years ago
node-pkg-configuration v1.1.0
configuration-node
Installation
npm install --save node-pkg-configuration
Usage
Config files:
Files in dir configuration/test
test:
hotelbook_params:
url: https://hotelbook.com/xml_endpoint
username: TESt_USERNAME
password: PASSWORD
logging: info
databases:
redis:
master:
username: R_USER
password: R_PASS
defaults:
port: 8081
logging: ignore
Files in dir configuration/defaults
defaults:
port: 8080
hotelbook_params:
area_mapping:
KRK: Krakow
MSK: Moscow
CHB: Челябинск
logging: debug
Import files:
Import with string params
import Config from 'node-pkg-configuration';
const config = new Config(`${__dirname}/configuration`, 'test');
Import with ENV params
import Config from 'node-pkg-configuration';
const config = new Config(process.env.CONFIG_PATH, process.env.STAGE);
CONFIG_PATH - should have full path to file. Exemple:
CONFIG_PATH=Users/user/projects/my-project/configurations
Import without params
import Config from 'node-pkg-configuration';
const config = new Config();
With this config search in .env file variables CONFIG_PATH and STAGE if you don't have this variables in .env, set default path: /configuration and STAGE: production
Get config data:
config.get() //return config object:
{
hotelbook_params: {
area_mapping: {
KRK: 'Krakow',
MSK: 'Moscow',
CHB: 'Челябинск',
},
url: 'https://hotelbook.com/xml_endpoint',
username: 'TESt_USERNAME',
password: 'PASSWORD',
},
logging: 'ignore',
databases: {
redis: {
master: {
username: 'R_USER',
password: 'R_PASS'
}
}
},
port: 8081,
}
config.get('port') //return:
8081;
config.get('hotelbook_params') //return object:
hotelbook_params: {
area_mapping: {
KRK: 'Krakow',
MSK: 'Moscow',
CHB: 'Челябинск',
},
url: 'https://hotelbook.com/xml_endpoint',
username: 'TESt_USERNAME',
password: 'PASSWORD',
}
config.get('hotelbook_params.area_mapping.KRK') //return:
'Krakow'
Contact us.
If you have any issues or questions, you are welcome to create an issue, or
You can write an Email to lwswnnscrm@gmail.com
or roquie0@gmail.com
License.
Released under the GNU GPL v3