$ npm i config-check
const cc = require('config-check')
const config = {
env: cc('NODE_ENV').default('production').exec(),
port: cc('PORT').default(8080).int().exec(),
redis: {
uri: cc('REDIS_URI').required().exec()
},
aws: {
secret: cc('AWS_SECRET').required().exec(),
key: cc('AWS_KEY').required().exec(),
region: cc('AWS_REGION').default('us-east-1').exec(),
endpoint: cc('AWS_ENDPOINT').exec(),
},
}
Enforces env var existence
cc('SOME_ENV_VAR').required()
Adds default value
cc('SOME_ENV_VAR').default('default value')
Enforces the value is an integer with casting
cc('SOME_ENV_VAR').int()
Enforces the value is a float with casting
cc('SOME_ENV_VAR').float()
Splits a string into a list, not safe Default delimiter is ','
const delimiter = ' '
cc('SOME_ENV_VAR').list(delimiter)
Returns the final value
cc('SOME_ENV_VAR').exec()
- standardjs linting
- 100% test coverage
Command | Description |
---|---|
lint | Checks project linting |
lint:fix | Auto fixes project lint errors |
test | Test runner |
test:watch | Test runner with watch |
coverage | Coverage checker |
changelog | Generate changelog |