1.0.1 • Published 8 years ago

@mariusc23/env v1.0.1

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

env

A simple way to retrieve environment variables.

Installation

npm install --save @mariusc23/env

Usage

// ES5
const env = require('@mariusc23/env');

exports.SECRET = env({ name: 'SECRET' });
// ES6
import env from '@mariusc23/env';

export const SECRET = env({ name: 'SECRET' });

Options

name: string

Variable name.

env({
  name: 'SECRET'
});

required: boolean

Throw an error if variable is not present in the environment.

env({
  name: 'SECRET',
  required: true
});

defaultValue: string

Return a default value if variable is not present in the environment.

env({
  name: 'SECRET',
  defaultValue: 'puppies'
});

transform(value): function

Transform the value before returning it.

env({
  name: 'OPTIONS',
  transform: JSON.parse
});

Global Defaults

You can set global defaults. This is useful when you are too lazy to define a file to hold all your configuration constants.

env.setDefault('NODE_ENV', 'development'); // hint: built in

env({ name: 'NODE_ENV' });
// => 'development'