npm.io
2.1.4 • Published 8 years ago

envr

Licence
MIT
Version
2.1.4
Deps
0
Size
11 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

envr

Checks for commandline parameters or environment variables to determine in which environment to run your application.

npm Travis node

Configuring the Environment

Reads the NODE_ENV variable

export NODE_ENV=production

values can be:

  • prodcution
  • live
  • integration
  • staging
  • testing
  • dev
  • development

where production === live, integration === staging and dev === development

The NODE_ENV variable is overriden by setting any of those flags:

--production (--live)
--integration (--staging)
--testing
--dev (--development)

API

Get the current environment

const envr = require('envr');

console.log(envr.env) // production, integration, testing or development

There are also methods to directl yquery the environment

const envr = require('envr');

envr.isProduction()
envr.isIntegration()
envr.isTesting()
envr.isDevelopment()

All of thoe methods throw errors if the environment was not set

Load environment aware js config files

Loads js config files from a directory using the pattern ${dirname}/config.${envr.env}.js. All toplevel properties of a config.js file that may reside in the same directory as the other config files will overrife properties of the environment specific config file. The configfiles msut export an obejct.

const envr = require('envr');

// async, __dirname is the dir containgin the configs
cosnt config = envr.config(__dirname);