convict-register
Registration helper for node-convict, a featureful configuration management library for Node.js.
With dotenv together, convict-register
expands convict
further by automatically registering all of the modules under the given folder to easily create a modular settings structures by splitting domain settings via files for large application.
Install
npm install convict-register
Usage
An sample structure of settings folder.
- settings/
db.js
redis.js
index.js
Sample in settings/db.js
.
moduleexports = username: format: String default: 'dbuser' env: 'DB_USER'
Sample in settings/index.js
.
const Settings = /* Arguments - abspath: absolute path to the folder with settings modules. - recursive: whether to recursively find all settings modules. - settings: top level settings values.*/moduleexports = env: doc: 'Deployment environment' format: String default: 'development' env: 'NODE_ENV' host: format: String default: '0.0.0.0' env: 'HOST' port: format: 'port' default: 9394 env: 'PORT' keys: doc: 'Application secret keys' format: Array default: env: 'SECRET'
Using settings elsewhere (e.g. main.js
):
dotenv const settings = console // 9394console // dbuser
The settings.convict
object is essentially a convict
object, meaning that you still have full capacity of convict.