@yuxilabs/gptp-core
Version:
Core validation, formatting and execution logic for the GPTP file format.
26 lines (25 loc) • 631 B
JavaScript
import dotenv from 'dotenv';
/**
* Loads variables from .env file into process.env.
*/
export function loadEnvFile() {
dotenv.config();
}
/**
* Manually inject env vars into process.env.
*/
export function loadEnvVars(vars) {
for (const [key, value] of Object.entries(vars)) {
process.env[key] = value;
}
}
/**
* Access env var safely. Throws if required but missing.
*/
export function getEnv(key, options) {
const value = process.env[key] ?? options?.default;
if (options?.required && !value) {
throw new Error(`Missing required environment variable: ${key}`);
}
return value;
}