Skip to content

skelet00r/config-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

config-check

Install

$  npm i config-check

Usage

  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(),
    },
  }

Methods

required()

Enforces env var existence

  cc('SOME_ENV_VAR').required()

default(value)

Adds default value

  cc('SOME_ENV_VAR').default('default value')

int()

Enforces the value is an integer with casting

  cc('SOME_ENV_VAR').int()

float()

Enforces the value is a float with casting

  cc('SOME_ENV_VAR').float()

list(delimiter)

Splits a string into a list, not safe Default delimiter is ','

  const delimiter = ' '
  cc('SOME_ENV_VAR').list(delimiter)

exec()

Returns the final value

  cc('SOME_ENV_VAR').exec()

Development

Requirements

  • standardjs linting
  • 100% test coverage

Npm run commands

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

LICENSE

DBAD for more info

About

Check all config vars and validate them

Resources

License

Stars

Watchers

Forks

Packages

No packages published