nobushi-config
v0.8.1
Published
The configuration store.
Downloads
11
Readme
nobushi-config
Configuration control library for PaaS like Heroku or Azure.
Quick start
Install nobushi-config
via NPM or YARN.
npm install nobushi-config
# or
yarn add nobuhsi-config
Create an application (app.js
):
const nc = require('nobushi-config');
const config = nc(process.env).defaults({
port: 3000,
databaseUrl: 'sqlite:database.sqlite',
});
console.log('port:', config.port);
console.log('databaseUrl:', config.databaseUrl);
Run app.js
:
$ node app.js
port: 3000
databaseUrl: sqlite:database.sqlite
# Overwrite configurations by environment variables.
$ export PORT='8080'
$ export DATABASE_URL='postgresql://username:password@hostname:5432/db'
$ node app.js
port: 8080
databaseUrl: postgresql://username:password@hostname:5432/db
Usage
Overwrite configurations
const config = nc(arguments...).defaults(defaultConfig);
Can overwrite defaultConfig
by nc
's arguments
. Different naming
conventions (such as camelCase, SNAKE_CASE, etc.) are considered the same
property. For example, DATABASE_URL
, databaseUrl
, database.url
and
database-url
are same property.
Support placeholder
The part surrounded by ${}
is interpreted as a placeholder and the
corresponding configuration value is expanded. The value following :
is used
as the value when the configuration value does not exist. For example:
const config = nc(process.env).default({
databaseUrl: 'postgresql://username:${DATABASE_PASSWORD:secret}@localhost:5432/db',
});