isDebug
isDebug is a simple module that returns true
or false
upon require.
If the result is true
then the environment is a debug environment.
if the result is false
then the environment is a production environment.
isDebug looks at two environment variables to determine the result:
NODE_ENV
- If this environment variable begins with the string "dev" or "deb",
then the result will be
true
- If this environment variable begins with the string "dev" or "deb",
then the result will be
DEBUG
- If this environment variable is set to anything, then the result will
be
true
- If this environment variable is set to anything, then the result will
be
If neither environment variable are present, then the result will be
false
(i.e. a "production" environment).
Example
const isdebug = console
Starting the above script with DEBUG=true node script.js
or NODE_ENV=development
will result in:
isdebug = true
To re-check the status, e.g. to determine if process.env
has been manipulated,
simply re-require the module:
console // falseprocessenvNODE_ENV = 'development'console // true