https://github.com/jimzhan/convict-register
Registration helper for node-convict, a featureful configuration management library for Node.js
https://github.com/jimzhan/convict-register
application automatic config configuration configuration-management convict env environment-variables javasacript json json-files node nodejs require-context schema settings validation
Last synced: about 1 month ago
JSON representation
Registration helper for node-convict, a featureful configuration management library for Node.js
- Host: GitHub
- URL: https://github.com/jimzhan/convict-register
- Owner: jimzhan
- License: apache-2.0
- Created: 2018-07-07T01:26:46.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-20T03:56:56.000Z (over 7 years ago)
- Last Synced: 2025-03-08T00:02:02.361Z (over 1 year ago)
- Topics: application, automatic, config, configuration, configuration-management, convict, env, environment-variables, javasacript, json, json-files, node, nodejs, require-context, schema, settings, validation
- Language: JavaScript
- Size: 286 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# convict-register
Registration helper for [node-convict](https://github.com/mozilla/node-convict), a featureful configuration management library for Node.js.
[](https://travis-ci.org/jimzhan/convict-register)
[](https://www.npmjs.com/package/convict-register)
[](https://github.com/airbnb/javascript)
[](http://commitizen.github.io/cz-cli/)
With [dotenv](https://github.com/motdotla/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
```shell
npm install convict-register
```
## Usage
An sample structure of settings folder.
```
- settings/
db.js
redis.js
index.js
```
Sample in `settings/db.js`.
```javascript
module.exports = {
username: {
format: String,
default: 'dbuser',
env: 'DB_USER',
},
}
```
Sample in `settings/index.js`.
```javascript
const Settings = 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 = new Settings({
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`):
```javascript
dotenv.config()
const settings = require('./settings')
console.log(settings.get('port')) // 9394
console.log(settings.get('db.username')) // dbuser
```
The `settings.convict` object is essentially a `convict` object, meaning that you still have full capacity of [convict](https://github.com/mozilla/node-convict).