Convenience functions to determine the current node environment in Feathers
npm install feathers-envhelpers --save
This plugin adds the following methods to the app object:
returns true if
- NODE_ENV is set to 'development'
- NOVE_ENV is not set or empty
returns true if NODE_ENV is set to 'production'
returns true if Feathers is running in environment with name 'name', eg. app.isEnv('staging')
returns process.env.NODE_ENV or 'development' if no value has been set
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
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
}
Copyright (c) 2018
Licensed under the MIT license.