feathers-envhelpers
v0.6.2
Published
Convenience functions get the current node environment
Downloads
203
Readme
feathers-envhelpers
Convenience functions to determine the current node environment in Feathers
Installation
npm install feathers-envhelpers --save
API
This plugin adds the following methods to the app object:
app.isDevelopment()
returns true if
- NODE_ENV is set to 'development'
- NOVE_ENV is not set or empty
app.isProduction()
returns true if NODE_ENV is set to 'production'
app.isEnv(name)
returns true if Feathers is running in environment with name 'name', eg. app.isEnv('staging')
app.getEnv()
returns process.env.NODE_ENV or 'development' if no value has been set
Environment validation
The plugin validates the value of NODE_ENV to ensure it is written in lowercase and throws an Error otherwise.
These values will pass:
NODE_ENV=production
NODE_ENV=
NODE_ENV=development
These will cause an error to be thrown:
NODE_ENV=PRODUCTION
NODE_ENV=Staging
How to use
Configure the Plugin:
const feathers = require('@feathersjs/feathers');
const envHelpers = require('feathers-envhelpers');
// Initialize the application
const app = feathers();
// Initialize the plugin
app.configure(envHelpers());
Then in your application code:
if (app.isDevelopment()){
// do something in development only
}
License
Copyright (c) 2018
Licensed under the MIT license.