@mangar2/config
v2.2.0
Published
Reads a configuration from a file
Downloads
4
Readme
Abstract
Provides function to manage configuration files
Contents
Meta
| | | | --- | --- | | File | config.js | | Abstract | Provides function to manage configuration files | | Author | Volker Böhm | | Copyright | Copyright ( c ) 2020 Volker Böhm | | License | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |
Global functions
All global non private functions are listed here
getCommandLineParameters
getCommandLineParameters (whiteList) => {Object}
Gets the command line parameters as object ( Key/value )
getCommandLineParameters Parameters
| Name | Type | Description |
| ---- | ---- | ---- | ---- | ----------- |
| whiteList
| Array
| list of supported arguments | |
getCommandLineParameters returns
| Type | Description |
| ---- | ----------- |
| Object
| object with key/value |
getEnvironment
getEnvironment (whiteList) => {string}
Gets the current environment name
- if --env or --environment is specified as parameter it takes the parameter value
- else if NODE_ENV is specified it takes the os environment variable value
- else the default 'development' is selected
getEnvironment Parameters
| Name | Type | Attribute | Description |
| ---- | ---- | ---- | ---- | ----------- |
| whiteList
| Array
| optional | provides a white list of supported environments . | |
getEnvironment returns
| Type | Description |
| ---- | ----------- |
| string
| the environment name limited by a white list . |
selectConfiguration
selectConfiguration (configuration)
Select the right configuration from a configuration object based on the current environment setting
selectConfiguration Parameters
| Name | Type | Description |
| ---- | ---- | ---- | ---- | ----------- |
| configuration
| Object
| configuration object for different environments | |
readConfiguration
readConfiguration (defaultName)
Reads the current configuration from a file
- If the file name is specified as command line parameter ( first parameter ) this file is read
- If the file name is not specified , it will read the default file from the current directory or up to 5 levels in parent directories
- Then it returns the active configuration , default is 'development' from the configuration file
- The active configuration is either specified by parameter ( '--env' or '--environment' ) or set in 'NODE_ENV'
readConfiguration Parameters
| Name | Type | Description |
| ---- | ---- | ---- | ---- | ----------- |
| defaultName
| string
| default configuration file name | |