Skip to content

electrode-io/electrode-confippet

Repository files navigation

Electrode Confippet NPM version Build Status

Confippet is a versatile, flexible utility for managing configurations of Node.js applications. It's simple to get started, and can be customized and extended to meet the needs of your app.


Contents

Features

  • Simple - Confippet's presetConfig automatically composes a single config object from multiple files. For most applications, no further customization is necessary.
  • Flexible - Supports JSON, YAML, and JavaScript config files.
  • Powerful - Handles complex multi-instance enterprise deployments.

Getting Started

In this example, we'll create two config files: a default file that always loads, and a production file that loads only when the NODE_ENV environment variable is set to production. We'll then import those files into a standard Node.js app.

Installation

npm install electrode-confippet --save

Basic Use

Make a config/ directory inside the main app directory, and put the following into a file named default.json in that directory:

{
  "settings": {
    "db": {
      "host": "localhost",
      "port": 5432,
      "database": "clients"
    }
  }
}

Next, add another file called production.json to the config/ directory, with this content:

{
  "settings": {
    "db": {
      "host": "prod-db-server"
    }
  }
}

Finally, in our Node.js app, we can import Confippet and use the configuration we've created:

const config = require("electrode-confippet").config;
const db = config.$("settings.db");
<