Coder Social home page Coder Social logo

pelias-config's Introduction

Installation

Greenkeeper badge

$ npm install pelias-config

NPM

Usage

Create a new Pelias config:

var config = require('pelias-config');

// use the default settings
var settings = config.defaults;

development settings

var config = require('pelias-config');

// generate development specific settings
var settings = config.generate();

local config

the easiest way to get a custom config is to create a file named ~/pelias.json.

you can copy the example file from here: https://github.com/pelias/config/blob/master/config/local.json

this file will be checked for settings whenever you run imports and will override the defaults; it is particularly useful for specifying datasource paths during development.

production settings

sysadmin and ops engineers can override the default settings on the server by launching any code which requires this module by supplying an ENV var with the path to their custom json config.

$ PELIAS_CONFIG=/path/to/settings/file.json node app.js

Note: by default the merge is deep (it replaces the defaults with any properties that are present in the env config). The developer can disable deep merging to use only local configuration settings.

var config = require('pelias-config');

// shallow merge config settings from a path supplied in the env var
var settings = config.generate( false );

// deep merge config settings from a path supplied in the env var
var settings = config.generate( true );
var settings = config.generate();

You can test the result of merging your env config with the following bash oneliner:

npm install pelias-config; \
PELIAS_CONFIG=/path/config.json \
node -e "console.log( require('pelias-config').generate().stringify() );";

Validation

Aside from deep, the generate function takes an additional parameter named schema that uses Joi to validate that the configuration is useable. An error is thrown if the generated configuration does not validate against the schema.

Exporting & Debugging

The generated config will be a mergeable object:

var config = require('pelias-config'),
    settings = config.generate();

// strip out all functions etc and produce a plain js object copy
var copy = settings.export();

You can pretty print the generated config:

var config = require('pelias-config'),
    settings = config.generate();

console.log( settings.stringify() );

see https://github.com/pelias/mergeable for a full list of methods

NPM Module

The pelias-config npm module can be found here:

https://npmjs.org/package/pelias-config

Contributing

Please fork and pull request against upstream master on a feature branch.

Pretty please; provide unit tests and script fixtures in the test directory.

Running Unit Tests

$ npm test

Continuous Integration

Travis tests every release against Node.js 4 and 6

Build Status

pelias-config's People

Contributors

bradh avatar dianashk avatar gibranparvez avatar greenkeeper[bot] avatar greenkeeperio-bot avatar hkrishna avatar missinglink avatar orangejulius avatar riordan avatar sevko avatar tigerlily-he avatar trescube avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.