0.1.0 • Published 8 years ago

check-environment v0.1.0

Weekly downloads
14
License
MIT
Repository
github
Last release
8 years ago

check-environment

Build Status Known Vulnerabilities

Description

This is a node.js module that will check currently set environment variables against a pre-defined specification.

Getting started

install using npm:

  • npm i -S check-environment

Add your env.yaml at the same level as your package.json and call this module at the top of the entrypoint to your app (i.e. app.js or index.js), like below;

const envCheck = require('check-environment')();

An example of a configuration file can be seen below;

---
NODE_ENV:
  required: true
  type: string
  format: "^(development|test|production)$"
  log: true

Documentation

Environment variable specification

Under the key of the name of the environment variable, an object with the following parameters:

ParamTypeDefaultDescription
requiredbooleanfalsewhether or not to auto-load the spec
typestring"any"either 'boolean', 'string', 'number or 'any'
formatstringnonea RegExp pattern string to use to validate the environment variable
or objectnonespecifying a RegExp pattern and modifiers in an object
format.patternstringnonea RegExp pattern string to use to validate the environment variable
format.flagsstringnonea string containing a combination of: m, i, and/or g to use as part of the validation pattern

Module: (options (optional)) ⇒ Checker

Creates and returns an instance of a Checker passing in the user supplied configuration options Name: none (module's sole export) Kind: function (synchronous)

Parameters

ParamTypeDefaultDescription
optionsobjectn/aconfiguration object
options.autoLoadbooleanwhether or not to auto-load the spec
options.specLocationstringthe location of the environment specification

Returns: an instance of Checker

Checker

Property: specLocation

Type: String Description: the location of the environment specification (Can be YAML or JSON)

Method: loadSpec()

Description: Loads the specification and checks it's validity.
NOTES:

  • automatically run on instantiation if autoLoad is not set to true

Method: check() => Object

Description: Checks environment variables against Returns: An object with keys equal to the names of set and valid environment variables, and their values converted to their specified type.
NOTE:

  • Requires loadSpec() to have been run first
  • automatically run on instantiation if autoLoad is not set to true
0.1.0

8 years ago

0.0.24

8 years ago

0.0.23

8 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago