Package Exports
- convict-register
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (convict-register) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
convict-register
Registration helper for node-convict, a featureful configuration management library for Node.js.
With dotenv together, convict-register expands the convict further by automatically registering all of the modules under the given folder, so that we can easily create a modular settings structures by splitting domain settings via files for large application.
Install
npm install convict-registerUsage
An sample structure of settings folder.
- settings/
db.js
redis.js
index.jsSample in settings/db.js.
module.exports = {
username: {
format: String,
default: 'dbuser',
env: 'DB_USER',
},
}Sample in settings/index.js.
const register = require('convict-register')
/*
Arguments
- abspath: absolute path to the folder with settings modules.
- recursive: whether to recursively find all settings modules.
- settings: top level settings values.
*/
module.exports = register(__dirname, false, {
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.config()
const settings = require('./settings')
console.log(settings.get('port')) // 9394
console.log(settings.get('db.username')) // dbuser
The settings object is essentially a convict object, meaning that you still have full capacity of convict.