Runtime agnostic SDK configuration via env vars (#2132)

* use std-env in getEnvVar

* add changeset
This commit is contained in:
nicktrn
2025-06-04 15:48:52 +01:00
committed by GitHub
parent eee0fb2198
commit 7ee0992a2f
2 changed files with 17 additions and 6 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"trigger.dev": patch
"@trigger.dev/core": patch
---
Runtime agnostic SDK config via env vars
+11 -6
View File
@@ -1,10 +1,15 @@
export function getEnvVar(name: string, defaultValue?: string): string | undefined {
// This could run in a non-Node.js environment (Bun, Deno, CF Worker, etc.), so don't just assume process.env is a thing
if (typeof process !== "undefined" && typeof process.env === "object" && process.env !== null) {
return process.env[name] ?? defaultValue;
}
import { env } from "std-env";
return defaultValue;
/**
* Get an environment variable with optional default value. Runtime agnostic.
*
* @param name The name of the environment variable.
* @param defaultValue The default value to return if the environment variable is not set.
* @returns The value of the environment variable, or the default value if the environment variable is not set.
*
*/
export function getEnvVar(name: string, defaultValue?: string): string | undefined {
return env[name] ?? defaultValue;
}
export function getNumberEnvVar(name: string, defaultValue?: number): number | undefined {