config
    Overview
    Insights & Analysis
    Code
    Versions
    Find an Expert
    Documentation
    Playground
    Issues
    Career Opportunities
    Alternatives
    Dependencies

config

Configuration control for production node deployments

3.2.2  •  Published 1 month ago  •  by Loren West  •  MIT License

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 leosuncin 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

License

May be freely distributed under the MIT license.

Copyright © 2010-2018 Loren West and other contributors

Dependencies

json5  ·  @types/node  ·  coffeescript  ·  cson  ·  hjson  ·  js-yaml  ·  properties  ·  semver  ·  toml  ·  ts-node  ·  typescript  ·  underscore  ·  vows  ·  x2js

Tags

conf
config
configuration
node-config
config-node
env
environment
Avoid unsafe or low quality packages
Warn or block the installation of vulnerable, badly licensed, deprecated, outdated, unmaintained, or unpopular packages. Integrates with your npm and pre-commit/build scripts
Just $9/month per developer

Popularity

Weekly Downloads
377.9K
Stars
4.3K

Issues and PRs

Activity

Last ver 1 month ago
Created 9 years ago
Last commit 1 month ago
5 days between commits

Sustainability

87 contributors

Technology

Node version: 10.15.3
87.5K unpacked

Legal and Compliance

MIT License
OSI Approved
0 vulnerabilities

Top Experts

Loren West
Maintainer, 188 commits, 113 merges, 2 PRs
Loren
215 commits
Mark Stosberg
Maintainer, 60 commits, 10 merges, 17 PRs
Works at RideAmigosCorp
imoses
23 commits, 7 PRs
Works at Twiggle
Elliott Foster
9 commits, 3 PRs
Works at Four Kitchens
Jason Felege
7 commits, 4 PRs