@studiohyperdrive/env
Environment helper used at Studio Hyperdrive.
Last updated 2 months ago by fabianmeul .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @studiohyperdrive/env 
SYNC missed versions from official npm registry.

Env

Environment utility for NodeJS.

Table of contents

Getting Started

Install the package

# NPM
npm install --save @studiohyperdrive/env

# Yarn
yarn add --save @studiohyperdrive/env

Usage

import Env from '@studiohyperdrive/env';

get

Fetches an environment variable as a string.

get(key: string, allowNull = false): string

Usage:

  const variable = Env.get('PARAM_NAME');
  const nullableVariable = Env.get('PARAM_NAME', true);

getAsBoolean

Casts the fetched environment variable to a boolean.

getAsBoolean(key: string): number

Usage:

  const variable = Env.getAsBoolean('PARAM_NAME');

getAsNumber

Casts the fetched environment variable to a number.

getAsNumber(key: string): number

Usage:

  const variable = Env.getAsNumber('PARAM_NAME');

getAsArray

Casts the fetched environment variable to an Array.

getAsArray(key: string, separator = ','): number

Usage:

  const variable = Env.getAsArray('PARAM_NAME', ';');

getAsObject

Casts the fetched environment variable to an object using JSON.parse.

getAsObject(key: string): number

Usage:

  const variable = Env.getAsObject('PARAM_NAME');

validateEnv

Validate process.env against a Joi Schema.

validateEnv(schema: Joi.Schema, options: Joi.ValidationOptions): ValidationResult

Usage:

  const validationResult = Env.validateEnv(schema, options);

validateEnvAsync

Validate process.env against a Joi Schema in an asynchronous fashion.

validateEnvAsync(schema: Joi.Schema, options: Joi.ValidationOptions): ValidationResult

Usage:

  const validationResult = await Env.validateEnvAsync(schema, options);

Current Tags

  • 1.0.3                                ...           latest (2 months ago)

4 Versions

  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           6 months ago
  • 1.0.1                                ...           6 months ago
  • 1.0.0                                ...           6 months ago

Copyright 2014 - 2016 © taobao.org |