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
| Parameter | Type | Description |
|---|---|---|
name | string | Environment variable name. Will first trim(); empty string directly return undefined. |
Return value
| Return | Type | Description |
|---|---|---|
| Environment variable values | string | Returns the value after trim if the variable exists and is not empty after trim. |
| Not found | undefined | The variable name is empty, the variable does not exist, or the variable value is empty. |
Data Source
| Operating position | Source | Description |
|---|---|---|
| CLI /Local runtime | process.env and workflow .env | executor will load .env in the workflow directory before running. |
| Desktop | Electron Local runtime environment and local project configuration | Desktop runs only local projects. |
| Server | environment variables and running environment saved by the server | Variables saved by the server web are readable at runtime. |
Read process
| Phase | Input | Result |
|---|---|---|
| workflow Code | Variable name | workflow.getEnv(name) |
| runtime env | process.env[name] | string after trim or undefined |
| provider / node | String value | For 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
| Rules | Description |
|---|---|
| Do not return empty string | A value of " " returns undefined. |
| Not responsible for default | The default value is explicitly handled in business code when required. |
| LLM provider also depend on it | createLLMProviderFromEnv() reads the LLM_* configuration through it. |