Source

utils/composeEnv.js

  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var pick_1 = __importDefault(require("lodash/pick"));
  7. // Config dot env
  8. require('dotenv').config();
  9. /**
  10. * Environment variables (dotenv) composer with empty check
  11. * @category utils
  12. * @module composeEnv
  13. */
  14. var composeEnv = function (keys) {
  15. var values = (0, pick_1.default)(process.env, keys);
  16. /**
  17. * Throw an error if any of the environment variables is not defined
  18. */
  19. (function () {
  20. var missingKeys = [];
  21. for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
  22. var key = keys_1[_i];
  23. var value = values[key];
  24. if (value === undefined)
  25. missingKeys.push(key);
  26. }
  27. if (missingKeys.length > 0)
  28. throw new Error("Value(s) undefined but required in environment: ".concat(missingKeys.join(', ')));
  29. })();
  30. return {
  31. keys: keys,
  32. values: values,
  33. };
  34. };
  35. exports.default = composeEnv;