Add getOptionalEnvVar function

Also add tests for it and `getRequiredEnvParam`
This commit is contained in:
Michael B. Gale
2025-10-24 14:58:07 +01:00
parent d75645b13f
commit ad35676669
2 changed files with 40 additions and 0 deletions

View File

@@ -673,6 +673,17 @@ export function getRequiredEnvParam(paramName: string): string {
return value;
}
/**
* Get an environment variable, but return `undefined` if it is not set or empty.
*/
export function getOptionalEnvVar(paramName: string): string | undefined {
const value = process.env[paramName];
if (value?.trim().length === 0) {
return undefined;
}
return value;
}
export class HTTPError extends Error {
public status: number;