@zulus/config
v1.0.1
Published
Validator for configuration files
Downloads
1
Maintainers
Readme
config
Validator for configuration files, based on Joi, loads configuration, based on process.env.NODE_ENV
property
npm i zulus/config
Structure
USAGE
Index config file
// config/index.js
const config = require('@dev/config');
const schema = require('./configSchema');
module.exports = config.loadConfig(__dirname, schema, null, 'config.#env');
Sample schema for validation
// configSchema.js
const Joi = require('joi');
module.exports = Joi.object({
mysql: Joi.object({
connectionLimit: Joi.number().min(1),
host: Joi.string().trim(),
port: Joi.number().min(1),
user: Joi.string(),
password: Joi.string(),
database: Joi.string(),
debug: Joi.boolean()
.default(false)
.optional()
}).strict(true),
aerospike: Joi.object({
hosts: Joi.array().items(
Joi.object({
addr: Joi.string(),
port: Joi.number().min(1)
})
),
log: Joi.object({
level: Joi.any(),
file: Joi.string()
}).optional(),
user: Joi.string().optional(),
password: Joi.string().optional(),
policies: Joi.object({}).optional(),
modlua: Joi.object({
systemPath: Joi.string(),
userPath: Joi.string()
}).optional(),
maxConnsPerNode: Joi.number().min(1)
}).strict(true)
});
API
config.loadConfig(configDir, schema, options, pattern)
Loads configuration from file, located in configDir
based on current NODE_ENV value.
May throw an error, if validation failed.
configDir
- path to directory, which contains all configuration filesschema
- Joi schema for validation of all config files, see Joi API[options]
- Custom Joi options for validation, see API[allowUnknown]
- allow unknown properties (defaulttrue
)[convert]
- try to convert string -> numbers[presence]
- default behaviour of validation, default `required
[pattern]
- pattern of config files, defaultconfig.#env
. Note, chain#env
will be replaced by current NODE_ENV value
Contributing
To start contributing do
git clone [email protected]:ZulusK/nodejs-config.git
git checkout develop
git checkout -b <your-branch-name>
The project is developed in accordance with the GitFlow methodology.
What it means
- All work you should do in your own local branch (naming is important, look below), then make pull request to develop branch
- Your local branch should not have conflicts with repository develop branch. To avoid it, before push to repository, do:
git pull origin develop # resolve all conflicts, if they exists git add --all git commit -m "fix conflicts" git push origin <your-branch-name>
- We use next naming of branches:
| branch template | description |
| ------------------------------------ | ----------------------------------------------------------- |
| feat/<short-feature-name>
| new feature, ex. feat-add-logger
|
| fix/<short-fix-name>
| fix of existing feature, ex. fix-logger
|
| refactor/<short-scope-description>
| refactor, linting, style changes, ex. style-update-eslint
|
| test/<short-scope-descriptiopn>
| tests, ex. test-db-connections
|
| docs/<short-scope-descriptiopn>
| documentation, ex. test-db-connections
|
Important, before push
We use eslint with this rules to lint code, before making pull request, lint your code:
npm run lint
Before making pull request, run tests
npm run test