https://github.com/euank/eunodeconfig
A simple config loader for nodejs. WIP
https://github.com/euank/eunodeconfig
Last synced: over 1 year ago
JSON representation
A simple config loader for nodejs. WIP
- Host: GitHub
- URL: https://github.com/euank/eunodeconfig
- Owner: euank
- License: apache-2.0
- Created: 2015-11-03T04:27:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-05T05:12:03.000Z (over 10 years ago)
- Last Synced: 2025-01-24T17:19:16.971Z (over 1 year ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EuNodeConfig
**NOTE, THIS IS A WORK IN PROGRESS AND NOT COMPLETE AT THIS TIME**
To see what works, look at the test(s).
Node config is a simple library for loading configuration from the environment
and various file formats. It allows your users to specify their configs in
various formats and takes care of parsing the formats appropriately for you.
## Usage
This module exports only one function: `loadConfig`.
```javascript
var configLoader = require('eu-node-config');
configLoader.loadConfig({
username: {
default: "bob", // A config with a default value can't be required
},
username2: "anotherDefaultFormat",
secure: {
required: true,
error: "Missing required config value: secure" // This default message will be printed if you do not supply your own. This can only be used if the config has a validation, such as required.
},
anotherConfigKey: {
error: true
},
finalConfigKey: {} // This config value will not be required and might not be in the object returned
}, {
configFolders: ['/etc/myconf'], // Optional, defaults to working directory and then process base directory
filePrefix: 'part-before-the-dot', // Optional, defaults to config
order: ["string", "environment", "json", "yaml", "defaults"], // Optional, defaults to the value shown left; earlier values will override later values
// other options include "js" to load from a .js file
configString: '{"key": "value"}', // The 'string' source above.
}, function(err, config) {
console.log("Config loaded: " + config);
});
// Alternately, promise style
configLoader.loadConfig({username: {default: "bob"}, {jsonData: '{"username":"bill"}'})
.then(function(config) {
console.log(Config loaded: " + config);
})
.error(function(err) {
console.log("Failed to load config: " + err);
});
```
## Formats supported
### .yaml, .json, and .js
From the above description, your config will be loaded from a file if it begins
with your filePrefix (default config) and ends with ".json" or ".yaml". If you
enable "loadJsConfigs" it will also load .js extension files.
### Environment variables
Environment variables matching either your config key or your config key
converted to upper-case and with camelcasing normalized to underscore
seperation will be used.
For example, the config key "configKey" will be accessed as either the
environment variable "configKey" or "CONFIG\_KEY"