1.2.3 • Published 11 years ago
embedded-config v1.2.3
node-embedded-config
Node configuration file loader with integrated environment variables.
Introduction
Embedded-config lets you define a default configuration and optionally overwrite them in different deployment environments (development, staging, production, etc).
The JSON configuration files allow for inclusion of environment variables using the following syntax in string values:
{
"db": "{MONGODB_URI}"
}
Here, MONGODB_URI is an environment variable in the server and its value will be replaced into the configuration when the file is loaded.
Usage
Create the config folder in your application directory and create the default configuration file.
$ mkdir config
$ vi config/default.json
{
"db": "{MYSQL_CONNECTION_URI}",
"secret_key": "1234567890"
}
Values in your configuration file based on NODE_ENV will be deeply merged into the default configuration.
$vi config/development.json
{
"db": "localhost"
}
Use the configuration in your code (config is a simple JavaScript object).
var config = require('embedded-config');
...
var db = mysql.connect(config.db);
...
Start the server.
$ NODE_ENV=development node index.js