0.8.1 • Published 6 years ago

nobushi-config v0.8.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

nobushi-config

NPM Build Status npm type definitions

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',
});

Author

kou64yama

0.8.1

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.1

6 years ago

0.4.0

6 years ago

0.5.0

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago