Blocco

Usage & Examples

< Prev.: API Back to main

Examples

File structure example:

| Notice: | the contents of the files listed below is an example; it is not necessary to use this particular data. | |–:|:–|

File: ProjectRoot/index.js

const Koa = require('koa');
const Settings = require('settings');

const app = new Koa();
const settings = new Settings({
    root: 'settings',
    env: 'prod'
});

(async () => {
    await settings.load();
    app.listen(settings.get('app.port'));
})();

File: ProjectRoot/settings/**/app.json

{
    "port": 3000,
    "autocorrectPort": true,
    "loglevel": "info",
    "featureFreeze": [
        "authorization"
    ]
}

File: ProjectRoot/settings/**/db.json

{
    "client": "pg",
    "connection": {
        "host": "127.0.0.1",
        "user": "postgres",
        "password": "SUP3RS3CR3T",
        "database": "stream_dev"
    }
}

Usage

Usage with knex and async/await syntax construction

const Settings = require('Blocco');
const Knex = require('kneex');
const settings = new Settings({
    environment: 'test',
    immutable: true,
    root: './settings'
});

(async () => {
    await settings.load();
    const knex = Knex(settings.get('db'));
})();
< Prev.: API Back to main