# config

All settings become available as `server.settings.app.<setting path>` within
the app and the plugins, for example `server.settings.app.kazana.admin.password`
or `server.settings.app.config.myApp.mySetting`.

Defaults can be set in the [config option](manifest.md#config) of the app &
plugin manifests, it can be overwritten with environment variables, CLI
arguments and `.kazanarc` configuration files. See [Sources & order of
configuration](#sources--order-of-configuration).

## Default settings

<table>
  <thead>
    <tr>
      <th aling=left>Setting Path</th>
      <th>Default / Example</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <strong>kazana.port</strong>
      </td>
      <td><code>5000</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.log.level</strong>
      </td>
      <td><code>warn</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.admin.username</strong><br>
        Database admin username
      </td>
      <td><code>kazana</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.admin.password</strong><br>
        Database admin password
      </td>
      <td><code>secret</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.backend.name</strong><br>
        When undefined, defaults to pouchdb-server's built-in "leveldown". Can be set to "couchdb" or any levelup storage back-ends: https://github.com/Level/levelup/wiki/Modules#storage-back-ends
      </td>
      <td><code>-no default-</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.backend.port</strong>
      </td>
      <td><code>4999</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.backend.location</strong><br>
        Location option as it gets passed to levelup https://github.com/Level/levelup#leveluplocation-options-callback
        If backend.name="couchdb", set the couchdb url without credententials, e.g. "https://my.couch.com"
      </td>
      <td><code>./.db</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.backend.log.file</strong><br>
        Does not apply if backend.name="couchdb"
      </td>
      <td><code>./.db/pouch.log</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.backend.log.level</strong><br>
        Does not apply if backend.name="couchdb"
      </td>
      <td><code>info</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.backend.config.file</strong><br>
        Does not apply if backend.name="couchdb"
      </td>
      <td><code>./.db/config.json</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.backend.timeout</strong><br>
        Time to connect database in milliseconds
      </td>
      <td><code>30000</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.db.rawData</strong><br>
        Name of database containing submitted raw data
      </td>
      <td><code>kazana-raw-data</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.db.integratedData</strong><br>
        Name of database containing integrated data
      </td>
      <td><code>kazana-raw-data</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.db.options</strong><br>
        Database ajax options, as passed to the PouchDB constructor.
      </td>
      <td><code>{ timeout: 10000 }</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.email.service</strong><br>
        Nodemailer Email Service
      </td>
      <td><code>gmail</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.email.auth.username</strong><br>
        Nodemailer Email Service Username
      </td>
      <td>e.g. <code>joe@example.com</code></td>
    </tr>
    <tr>
      <td>
        <strong>kazana.email.auth.password</strong><br>
        Nodemailer Email Service Password
      </td>
      <td>e.g. <code>secret</code></td>
    </tr>
  </tbody>
</table>

## Custom app / plugin configuration

All app / plugin settings must be prefixed with the name is at is set in the
[manifest name option](kazana-manifest.md#name).

## Sources & order of configuration

Kazana is using the [rc](https://www.npmjs.com/package/rc) package for configuration.
The [config option](manifest.md#config) of the app & plugin manifests is passed
in as default, then rc is looking at these places

- command line arguments (parsed by [minimist](https://www.npmjs.com/package/minimist))
- environment variables prefixed with kazana\_
  - or use "\_\_" to indicate nested properties
  - (e.g. appname\_foo\_\_bar\_\_baz => foo.bar.baz)
- if you passed an option --config file then from that file
- a local .kazanarc or the first found looking in ./ ../ ../../ ../../../ etc.
- $HOME/.kazanarc
- $HOME/.kazana/config
- $HOME/.config/kazana
- $HOME/.config/kazana/config
- /etc/kazanarc
- /etc/kazana/config
- the defaults object you passed in.

All configuration sources that were found will be flattened into one object, so that sources earlier in this list override later ones.
