You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

execution-environment

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

execution-environment

This module serves as a helper to expose the current execution environment.

1.1.6
latest
Source
npmnpm
Version published
Weekly downloads
3
-76.92%
Maintainers
4
Weekly downloads
 
Created
Source

execution-environment

Build Status devDependency Status devDependency Status

This module serves as a helper to expose the current execution environment by reading NODE_ENV environment variable.

Installation

$ npm install execution-environment --save

Example usage

When writing a module, you may want to add conditional logic based on the execution environment. By default, the module sets default values for the dev, test and prod environments:

Default Values

  • isDev: ['dev', 'development']
  • isTest: ['test']
  • isProd: ['prod', 'production']
var environment = require('environment');

var Ajax = {
  get: function(method, path, params) {
    if (environment.isTest()) {
      throw new Error('Attempted to make a network call in the test environment. Shame!');
    }

    fetch(method, path, params);
  }
};

module.exports = Ajax;

When Ajax#get is executed in the test environment (defined by setting NODE_ENV=test), environment.isTest() will return true.

Additionally, custom environments and values can be registered on the environment module using registerEnvironments. The following code will register staging and canary environments, which will look for ['staging', 'stg'] and ['canary'] NODE_ENV values, respectively. Code that modifies the environment keys and values should live in a setup or config file rather modules that are require environment.

var environment = require('environment');

environment.registerEnvironments({
  staging: ['staging', 'stg'],
  canary: ['canary']
});

Usage with custom environments

var environment = require('environment');

var Tracking = {
  trackEvent: function(name, category, payload) {
    if (environment.staging() || environment.canary()) {
      return;
    }

    trackEsp(name, category, payload);
  }
};

module.exports = Tracking;

FAQs

Package last updated on 03 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts