## etc
**Kind**: global class
* [etc](#etc)
* [new etc()](#new_etc_new)
* [.createConfig(filePath)](#etc+createConfig)
* [.packageJson([dir])](#etc+packageJson) ⇒ object
* [.packageJsonDir(dir)](#etc+packageJsonDir) ⇒ string
* [.parseJSONPath(filePath)](#etc+parseJSONPath) ⇒ object
* [.projectRoot()](#etc+projectRoot) ⇒ string
* [.parseJSON(filePath)](#etc+parseJSON) ⇒ object
* [.argv()](#etc+argv) ⇒ object
* [.directory(dir)](#etc+directory) ⇒ object
* [.parseYAML([filePath])](#etc+parseYAML) ⇒ object
* [.env([dir])](#etc+env) ⇒ object
* [.getFilePath(configType, fileName)](#etc+getFilePath)
* [.readConfigData(configType, filePath, config)](#etc+readConfigData)
* [.addConfig(configType, filePath, config)](#etc+addConfig)
* [.deleteConfig(configType, filePath, config)](#etc+deleteConfig)
* [.editConfig(configType, filePath, config)](#etc+editConfig)
* [.save(configType, filePath, config)](#etc+save)
* [.all()](#etc+all)
### new etc()
constructor
### etc.createConfig(filePath)
create configuration file in filePath if it does not exists
**Kind**: instance method of [etc](#etc)
| Param | Type | Description |
| --- | --- | --- |
| filePath | string | with the extensions [.json|.yaml|.yml|.env]if filename is supplied instead of absolute path, create in /etc/{appName} or in ~/etc/{appName} if permission is denied for /etc |
### etc.packageJson([dir]) ⇒ object
Read package.json [1] of current project or [2] from any other location.
If relative path is supplied for dir such as package.json or node-etc/package.json(=node-etc), the file will we looked for in [1] the cwd path moving down one level till it is found, [2] in /etc/${appName}, [3] in ~/etc/${appName}, [4] {projectRoot}/etc, [5] {projectRoot}/.etc, [6] {projectRoot}/config, [7] {projectRoot}/config
**Kind**: instance method of [etc](#etc)
**Returns**: object - - Returns json object found or empty object
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [dir] | string | "'package.json'" | Either absolute or relative path, with/without package.json at the end. |
### etc.packageJsonDir(dir) ⇒ string
Get path to package.json read by packageJson
**Kind**: instance method of [etc](#etc)
**Returns**: string - the path to the package.json read by packageJson
| Param | Type | Default |
| --- | --- | --- |
| dir | string | "package.json" |
### etc.parseJSONPath(filePath) ⇒ object
Read json file and return path if json file is valid
**Kind**: instance method of [etc](#etc)
**Returns**: object - - Returns json object found or empty object
| Param | Type | Description |
| --- | --- | --- |
| filePath | string | relative or absolute path of file to read. If relative path is supplied for dir such as package.json or node-etc/package.json(=node-etc), the file will we looked for in [1] the cwd path moving down one level till it is found, [2] in /etc/${appName}, [3] in ~/etc/${appName}, [4] {projectRoot}/etc, [5] {projectRoot}/.etc, [6] {projectRoot}/config, [7] {projectRoot}/config |
### etc.projectRoot() ⇒ string
Get the root dir of current project by locating package.json
**Kind**: instance method of [etc](#etc)
**Returns**: string - - project root directory
### etc.parseJSON(filePath) ⇒ object
Read json file
**Kind**: instance method of [etc](#etc)
**Returns**: object - - Returns json object found or empty object
| Param | Type | Description |
| --- | --- | --- |
| filePath | string | relative or absolute path of file to read. If relative path is supplied for dir such as package.json or node-etc/package.json(=node-etc), the file will we looked for in [1] the cwd path moving down one level till it is found, [2] in /etc/${appName}, [3] in ~/etc/${appName}, [4] {projectRoot}/etc, [5] {projectRoot}/.etc, [6] {projectRoot}/config, [7] {projectRoot}/config |
### etc.argv() ⇒ object
return command line arguments
**Kind**: instance method of [etc](#etc)
**Returns**: object - - Returns object containing command line arguments
### etc.directory(dir) ⇒ object
read configuration from .yaml/.yml, .env and json files in given directory.
**Kind**: instance method of [etc](#etc)
| Param | Type | Description |
| --- | --- | --- |
| dir | string | absolute path of directory |
### etc.parseYAML([filePath]) ⇒ object
Read yaml file
**Kind**: instance method of [etc](#etc)
**Returns**: object - - Returns json object found or empty object
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [filePath] | string | "'conf'" | relative or absolute path of file to read, with either .yaml/.yml extension or without. If argument supplied is file.yaml, but file.yml is found instead, file.yml will be returned. If relative path is supplied for filePath such as config.yaml or node-etc/config.yaml(=node-etc/config), the file will we looked for in [1] the cwd path moving down one level till it is found, [2] in /etc/${appName}, [3] in ~/etc/${appName}, [4] {projectRoot}/etc, [5] {projectRoot}/.etc, [6] {projectRoot}/config, [7] {projectRoot}/config |
### etc.env([dir]) ⇒ object
Loads environment variables from a .env file in either [1] current project or [2] from any other location and returns process.env. If dir is not supplied, the function moves up the directories in the cwd path and returns the first .env file found.
If absolute path is not given for dir, it also loads .env from /etc/{dir}. If dir is not given, it is taken as the program name as contained in the package.json file in the root directory of the project.
**Kind**: instance method of [etc](#etc)
**Returns**: object - - Returns json object found or empty object
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [dir] | string | "''" | directory name from which to read .env file. Can be either a directory name or absolute path of directory |
### etc.getFilePath(configType, fileName)
Get filepath if file with given name exists in: [1] the cwd path moving down one level till it is found [2] /etc/${appName} [3] ~/etc/${appName} [4] {projectRoot}/etc [5] {projectRoot}/.etc [6] {projectRoot}/config [7] {projectRoot}/config
**Kind**: instance method of [etc](#etc)
| Param | Type |
| --- | --- |
| configType | 'json' \| 'yaml' \| 'yml' \| 'env' |
| fileName | string |
### etc.readConfigData(configType, filePath, config)
readConfiguration of configType from given path
**Kind**: instance method of [etc](#etc)
| Param | Type | Description |
| --- | --- | --- |
| configType | 'json' \| 'yaml' \| 'yml' \| 'env' | |
| filePath | string | filename with/without extension/ absolute path |
| config | object | |
### etc.addConfig(configType, filePath, config)
Add new values to config/modify existing ones
**Kind**: instance method of [etc](#etc)
| Param | Type | Description |
| --- | --- | --- |
| configType | 'json' \| 'yaml' \| 'yml' \| 'env' | |
| filePath | string | filename with/without extension/ absolute path |
| config | object | |
### etc.deleteConfig(configType, filePath, config)
Delete values from config
**Kind**: instance method of [etc](#etc)
| Param | Type | Description |
| --- | --- | --- |
| configType | 'json' \| 'yaml' \| 'yml' \| 'env' | |
| filePath | string | filename with/without extension/ absolute path |
| config | array | fields to remove |
### etc.editConfig(configType, filePath, config)
Add new values to config/modify existing ones
**Kind**: instance method of [etc](#etc)
| Param | Type | Description |
| --- | --- | --- |
| configType | 'json' \| 'yaml' \| 'yml' \| 'env' | |
| filePath | string | filename with/without extension/ absolute path |
| config | object | |
### etc.save(configType, filePath, config)
Save config values
**Kind**: instance method of [etc](#etc)
| Param | Type | Description |
| --- | --- | --- |
| configType | 'json' \| 'yaml' \| 'yml' \| 'env' | |
| filePath | string | absolute path |
| config | array | fields to save |
### etc.all()
Load all configurations
**Kind**: instance method of [etc](#etc)