0.0.1 • Published 7 years ago

@toki/toki-config-file v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

Toki-Config-File

Loads configuration from static file and returns it as an object

This is the static file configuration loader for the Toki project.

Lead Maintainer: Rob Horrigan

Build Status Known Vulnerabilities NSP Status

Install Dependencies

Install the dependencies based on package.json.

make install

Test Project

Run tests locally.

make test

Example

To get started, create a config directory at the root of your project then add a default.js file with the following format:

'use strict';

const configuration = {
    toki: {
        routes: [
            {
                path       : '/example',
                httpAction : 'GET',
                tags       : ['api'],
                description: 'Example endpoint',
                actions    : [
                    {
                        name: 'action 1',
                        type: 'http'
                    },
                    [
                        {
                            name: 'action 2',
                            type: 'http'
                        },
                        {
                            name: 'action 3',
                            type: 'http'
                        }
                    ]
                ]
            }
        ]
    }
};

module.exports = configuration;

NOTE: If set, toki-config will use your NODE_ENV to determine which configuration to load.

$: echo $NODE_ENV
production

Will load configuration at config/production.js


'use strict';

const Promise = require('bluebird');
const Config = require('toki-config-file');
const config = new Config();

const logConfig = () => {

    config.get()
        .then((configuration) => {
            console.log(configuration.routes[0].path) // /example
        })
        .catch((err) => {
            throw err;
        });
};

module.exports = () => {

    return Promise.resolve()
        .bind()
        .then(logConfig)
        .catch(function(err) {
            console.log(err);
        })
};