# Config

Easy configuration. The basis of every project.

## Config file
The config file is located under ```config/config.json```.

```javascript
{
    // Only modules listed here will be loaded on the backend.
    // client modules are wired up in the config/routes.js file,
    // currently they are not effected, however as a best practice
    // always list the modules here that you are using.
    //
    // Values here are the names of the directories under /modules
    "modules": [
        "mongodb",
        "todos"
    ],

    // The port of the server
    "port": 8080,

    // Default loglevel, can be changed during runtime from any module
    "loglevel": "info",

    // MongoDB specific config
    // Currently only the url of the running mongod instance can be set.
    "mongodb": {
        "url": "mongodb://localhost"
    }
}
```

## Accessing the config

In any module you can easily access the config from the registry:

```javascript
const registry = require('core/server/registry');
const config = registry.get('config');
```

## Where is the config file?

Right now the config file is ```/config/config.json```
We are planning to use Yaml in the future.

## How to retrieve a value?

```javascript
const registry = require('core/server/registry');
const config = registry.get('config');
let foo = config.get('foo');
```

## Default values
What happens when a value is not defined in the config? We can provide a fallback easily.

```javascript
const registry = require('core/server/registry');
const config = registry.get('config');
let foo = config.get('foo', 'Default value');
let bar = config.get('bar', {a: 1, b: 2});
```

## Command line?
Yes, of course. Command line parameters are always overwriting the values in the config file.
Example:
```bash
$> gulp run --foo="something"
```

```javascript
const registry = require('core/server/registry');
const config = registry.get('config');
let foo = config.get('foo'); // will return 'something', regardless what is in the config file
```
