in device/core/src/module_client.ts [393:416]
static fromEnvironment(transportCtor: any, callback?: Callback<ModuleClient>): Promise<ModuleClient> | void {
return callbackToPromise((_callback) => {
// Codes_SRS_NODE_MODULE_CLIENT_13_033: [ The fromEnvironment method shall throw a ReferenceError if the callback argument is falsy or is not a function. ]
if (!_callback || typeof (_callback) !== 'function') {
throw new ReferenceError('callback cannot be \'' + _callback + '\'');
}
// Codes_SRS_NODE_MODULE_CLIENT_13_026: [ The fromEnvironment method shall invoke callback with a ReferenceError if the transportCtor argument is falsy. ]
if (!transportCtor) {
_callback(new ReferenceError('transportCtor cannot be \'' + transportCtor + '\''));
return;
}
// Codes_SRS_NODE_MODULE_CLIENT_13_028: [ The fromEnvironment method shall delegate to ModuleClient.fromConnectionString if an environment variable called EdgeHubConnectionString or IotHubConnectionString exists. ]
// if the environment has a value for EdgeHubConnectionString then we use that
const connectionString = process.env.EdgeHubConnectionString || process.env.IotHubConnectionString;
if (connectionString) {
ModuleClient._fromEnvironmentNormal(connectionString, transportCtor, _callback);
} else {
ModuleClient._fromEnvironmentEdge(transportCtor, _callback);
}
}, callback);
}