@studiohyperdrive/env
v1.0.4
Published
Environment helper used at Studio Hyperdrive.
Downloads
170
Maintainers
Keywords
Readme
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);