UNPKG

wundertec-core

Version:

Librería estándar de utilidades e integraciones AWS + helpers generales

32 lines (31 loc) 1.06 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadEnv = loadEnv; exports.getConfig = getConfig; const dotenv_1 = __importDefault(require("dotenv")); /** * Carga variables de entorno desde un archivo .env. * @param path Ruta al archivo .env (por defecto busca en la raíz). */ function loadEnv(path) { dotenv_1.default.config({ path }); } /** * Obtiene el valor de una variable de entorno. * @param key Nombre de la variable. * @param defaultValue Valor por defecto si no existe. * @throws Error si no existe y no se proporcionó defaultValue. * @returns Valor de la variable o defaultValue. */ function getConfig(key, defaultValue) { const value = process.env[key]; if (value == null) { if (defaultValue != null) return defaultValue; throw new Error(`Configuration error: Missing environment variable ${key}`); } return value; }