Configure your Node.js Applications
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.).
This gives your application a consistent configuration interface shared among a growing list of npm modules also using node-config.
- 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
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
Use configs in your code:
const config = ;//...const dbConfig = config;db;if configconst detail = config;//...
config.get() will throw an exception for undefined keys to help catch typos and missing values.
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
dbName elements of
will come from the
default.json file, and the
host element will
come from the
production.json override file.
- Configuration Files
- Common Usage
- Environment Variables
- Reserved Words
- Command Line Overrides
- Multiple Node Instances
- Sub-Module Configuration
- Configuring from a DB / External Source
- Securing Production Config Files
- External Configuration Management Tools
- Examining Configuration Sources
- Using Config Utilities
- Upgrading from Config 0.x
- Webpack usage
If you still don't see what you are looking for, here are some more resources to check:
- The wiki may have more pages which are not directly linked from here.
- Review questions tagged with node-config on StackExchange. These are monitored by
- Search the issue tracker. Hundreds of issues have already been discussed and resolved there.
May be freely distributed under the MIT license.
Copyright (c) 2010-2020 Loren West and other contributors