GithubHelp home page GithubHelp logo

hhy5277 / node-config Goto Github PK

View Code? Open in Web Editor NEW

This project forked from node-config/node-config

0.0 2.0 0.0 2.41 MB

Node.js Application Configuration

License: Other

JavaScript 97.24% CoffeeScript 0.07% TypeScript 1.47% Shell 1.23%

node-config's Introduction

Configure your Node.js Applications

NPM   Build Status   release notes

Introduction

Node-config organizes hierarchical configurations for your app deployments.

It lets you define a set of default parameters, and extend them for different deployment environments (development, qa, staging, production, etc.).

Configurations are stored in configuration files within your application, and can be overridden and extended by environment variables, command line parameters, or external sources.

This gives your application a consistent configuration interface shared among a growing list of npm modules also using node-config.

Project Guidelines

  • Simple - Get started fast
  • Powerful - For multi-node enterprise deployment
  • Flexible - Supporting multiple config file formats
  • Lightweight - Small file and memory footprint
  • Predictable - Well tested foundation for module and app developers

Quick Start

The following examples are in JSON format, but configurations can be in other file formats.

Install in your app directory, and edit the default config file.

$ npm install config
$ mkdir config
$ vi config/default.json
{
  // Customer module configs
  "Customer": {
    "dbConfig": {
      "host": "localhost",
      "port": 5984,
      "dbName": "customers"
    },
    "credit": {
      "initialLimit": 100,
      // Set low for development
      "initialDays": 1
    }
  }
}

Edit config overrides for production deployment:

 $ vi config/production.json
{
  "Customer": {
    "dbConfig": {
      "host": "prod-db-server"
    },
    "credit": {
      "initialDays": 30
    }
  }
}

Use configs in your code:

const config = require('config');
//...
const dbConfig = config.get('Customer.dbConfig');
db.connect(dbConfig, ...);

if (config.has('optionalFeature.detail')) {
  const detail = config.get('optionalFeature.detail');
  //...
}

config.get() will throw an exception for undefined keys to help catch typos and missing values. Use config.has() to test if a configuration value is defined.

Start your app server:

$ export NODE_ENV=production
$ node my-app.js

Running in this configuration, the port and dbName elements of dbConfig will come from the default.json file, and the host element will come from the production.json override file.

Articles

Further Information

If you still don't see what you are looking for, here more resources to check:

Contributors

lorenwest markstos elliotttf jfelege leachiM2k josx
enyo arthanzel eheikes th507 Osterjour nsabovic
BadgerBadgerBadgerBadger simon-scherzinger axelhzf benkroeger fgheorghe IvanVergiliev
jpwilliams jaylynch jberrisch kgoerlitz bertho-zero leonardovillela
nitzan-shaked robertrossmann roncli superoven wmertens XadillaX

License

May be freely distributed under the MIT license.

Copyright (c) 2010-2018 Loren West and other contributors

node-config's People

Contributors

arthanzel avatar badgerbadgerbadgerbadger avatar bertho-zero avatar cunneen avatar eheikes avatar elliotttf avatar enyo avatar imoses avatar jacobemerick avatar jaylynch avatar jberrisch avatar jfelege avatar josx avatar kgoerlitz avatar leachim2k avatar leonardovillela avatar lorenwest avatar markstos avatar ncuillery avatar nitzan-shaked avatar nsabovic avatar osterjour avatar patrickpilch avatar robertrossmann avatar roncli avatar simon-scherzinger avatar superoven avatar th507 avatar wmertens avatar xadillax 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.