1.1.0 • Published 10 years ago
bootenv v1.1.0
-NODE
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 --saveManual Installation
git clone git@github.com:bootenv/bootenv-node.gitthis repository- change into the new directory
bootenv-node nvm usenpm installnpm link
Run tests
npm testUsage
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
- 1.0.0
- 1.1.0 (current)
