bootenv

1.1.0 • Public • Published

>bootenv-NODE

NPM

license engine npm Build Status Coverage Status

It’s simple! Node.js utility methods to make using the environment properties more pleasant. :wq

Prerequisites

You will need the following things properly installed on your computer.

Installation

NPM

npm install bootenv --save

Manual Installation

  • git clone git@github.com:bootenv/bootenv-node.git this repository
  • change into the new directory bootenv-node
  • nvm use
  • npm install
  • npm link

Run tests

npm test

Usage

Working with Environment Properties

Environment is a feature that allow you to define different components and settings based on the Environment properties.

Getting Environment properties in your code

There are three useful methods to get the Environment properties:

  • environment#getProperty(String)
  • environment#getProperty(String, String)
  • environment#getOptionalProperty(String)

The first method returns the Environment property value if the value exists (use only if you are 100% sure that the environment has a key) if not found returns null.

The second method returns the Environment property value if the key exists, otherwise returns the default value!

The last method returns a Javascript Optional property representation!

Please, take a look in the code below:

var environment = require('bootenv').environment;
 
var SEND_EMAIL_PROPERTY = 'SEND_EMAIL',
    EMAIL_ADDRESS_PROPERTY = 'EMAIL_ADDRESS',
    DEFAULT_EMAIL_ADDRESS_PROPERTY = 'DEFAULT_EMAIL_ADDRESS',
    DEFAULT_EMAIL_ADDRESS = 'support@bootenv.org';
    
...
 
if(environment.supportsOr(SEND_EMAIL_PROPERTY, false)) {
  var address = environment.getOptionalProperty(EMAIL_ADDRESS_PROPERTY);
  if(address.isPresent()){
    var email = address.get();
    console.info("Sending email to [%s]...", email);    
    ...
  } else {
    var email = environment.getPropertyOr(DEFAULT_EMAIL_ADDRESS_PROPERTY, DEFAULT_EMAIL_ADDRESS);
    console.info("Sending email to default address [%s]...", email);  
    ...
  }
} else {
  console.info('Not email send!');
}

Further Reading / Useful Links

Versions

License

Apache-2.0

Package Sidebar

Install

npm i bootenv

Weekly Downloads

0

Version

1.1.0

License

Apache-2.0

Last publish

Collaborators

  • bootenv
  • acactown
  • cesarizu