@mariusc23/env

1.0.1 • Public • Published

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'

Package Sidebar

Install

npm i @mariusc23/env

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • mariusc23