Environment

Documentation of how to use Meteor.EnvironmentVariable

Meteor runs most app code within Fibers, which allows keeping track of the context a function is running in. Meteor.EnvironmentVariable works with Meteor.bindEnvironment, promises, and many other Meteor API’s to preserve the context in async code. Some examples of how it is used in Meteor are to store the current user in methods, and record which arguments have been checked when using audit-argument-checks.

const currentRequest = new Meteor.EnvironmentVariable();

function log(message) {
  const requestId = currentRequest.get() || 'None';
  console.log(`[${requestId}]`, message);
}


currentRequest.withValue('12345', () => {
  log('Handling request'); // Logs: [12345] Handling request
});
Anywhere
import { Meteor } from 'meteor/meteor'
(meteor/dynamics_nodejs.js, line 21)

Constructor for EnvironmentVariable

Anywhere
import { Meteor } from 'meteor/meteor'
(meteor/dynamics_nodejs.js, line 27)

Return value of environment variable if available

Set the environment variable to the given value while a function is run

Arguments

value Any

Value the environment variable should be set to

func Function

The function to run

Stores the current Meteor environment variables, and wraps the function to run with the environment variables restored. On the server, the function is wrapped within a fiber.

Arguments

func Function

Function that is wrapped

onException Function
_this Object

Optional this object against which the original function will be invoked

Edit on GitHub
// search box