Skip to content

crijke/feathers-envhelpers

Repository files navigation

feathers-envhelpers

Build Status Code Climate Test Coverage Dependency Status Download Status

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.

About

Convenience functions to determine the current node environment in Feathers

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •