Skip to content

Runtime agnostic SDK configuration via env vars #2132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/flat-pianos-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"trigger.dev": patch
"@trigger.dev/core": patch
---

Runtime agnostic SDK config via env vars
17 changes: 11 additions & 6 deletions packages/core/src/v3/utils/getEnv.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down