Skip to main content

getEnv

workflow.getEnv() reads the environment variables in the current runtime environment. It will trim the variable name and variable value. If the variable name is empty, the variable does not exist, or the variable value is empty after trim, it will return undefined.

Signature

workflow.getEnv(name: string): string | undefined

Parameter

ParameterTypeDescription
namestringEnvironment variable name. Will first trim(); empty string directly return undefined.

Return value

ReturnTypeDescription
Environment variable valuesstringReturns the value after trim if the variable exists and is not empty after trim.
Not foundundefinedThe variable name is empty, the variable does not exist, or the variable value is empty.

Data Source

Operating positionSourceDescription
CLI /Local runtimeprocess.env and workflow .envexecutor will load .env in the workflow directory before running.
DesktopElectron Local runtime environment and local project configurationDesktop runs only local projects.
Serverenvironment variables and running environment saved by the serverVariables saved by the server web are readable at runtime.

Read process

PhaseInputResult
workflow CodeVariable nameworkflow.getEnv(name)
runtime envprocess.env[name]string after trim or undefined
provider / nodeString valueFor configuration of API key, base URL, model name, etc.

Example

const apiKey = workflow.getEnv("MY_API_KEY");

if (apiKey === undefined) {
throw new workflow.WorkflowError({
type: "input_validation",
message: "Missing MY_API_KEY.",
});
}

Precautions

RulesDescription
Do not return empty stringA value of " " returns undefined.
Not responsible for defaultThe default value is explicitly handled in business code when required.
LLM provider also depend on itcreateLLMProviderFromEnv() reads the LLM_* configuration through it.