Skip to content

Commit 7ee0992

Browse files
authored
Runtime agnostic SDK configuration via env vars (#2132)
* use std-env in getEnvVar * add changeset
1 parent eee0fb2 commit 7ee0992

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

.changeset/flat-pianos-live.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Runtime agnostic SDK config via env vars

packages/core/src/v3/utils/getEnv.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
export function getEnvVar(name: string, defaultValue?: string): string | undefined {
2-
// This could run in a non-Node.js environment (Bun, Deno, CF Worker, etc.), so don't just assume process.env is a thing
3-
if (typeof process !== "undefined" && typeof process.env === "object" && process.env !== null) {
4-
return process.env[name] ?? defaultValue;
5-
}
1+
import { env } from "std-env";
62

7-
return defaultValue;
3+
/**
4+
* Get an environment variable with optional default value. Runtime agnostic.
5+
*
6+
* @param name The name of the environment variable.
7+
* @param defaultValue The default value to return if the environment variable is not set.
8+
* @returns The value of the environment variable, or the default value if the environment variable is not set.
9+
*
10+
*/
11+
export function getEnvVar(name: string, defaultValue?: string): string | undefined {
12+
return env[name] ?? defaultValue;
813
}
914

1015
export function getNumberEnvVar(name: string, defaultValue?: number): number | undefined {

0 commit comments

Comments
 (0)