@studiohyperdrive/env
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.416latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.416
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i @studiohyperdrive/env

Weekly Downloads

16

Version

1.0.4

License

ISC

Unpacked Size

22.6 kB

Total Files

16

Last publish

Collaborators

  • npieter
  • wouterheirstrate
  • ekincia
  • bertyhell
  • shd-developer
  • ian-emsens-shd
  • jeroenvalcke
  • tom-odb
  • brilniels
  • thomasbormans
  • sanderh
  • laurenspeeters
  • rednas
  • denisvalcke
  • ibenvandeveire