It’s simple! Node.js utility methods to make using the environment properties more pleasant.
:wq
You will need the following things properly installed on your computer.
npm install bootenv --save
git clone git@github.com:bootenv/bootenv-node.git
this repository- change into the new directory
bootenv-node
nvm use
npm install
npm link
npm test
Environment is a feature that allow you to define different components and settings based on the Environment properties.
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!');
}
- 1.0.0
- 1.1.0 (current)