Ende.Env
interface · requires --allow-env
interface Ende.EnvAn interface containing methods to interact with the process environment variables.
Environment variables can also be loaded from a .env file by using the
--env-file flag when running an Ende program:
ende run --env-file=.env --allow-env main.ts
If --env-file is specified without a value, it defaults to loading .env
from the current working directory:
ende run --env-file --allow-env main.ts
Learn more at the Ende docs.
Methods
get
get(key: string): string | undefinedRetrieve the value of an environment variable.
Returns undefined if the supplied environment variable is not defined.
console.log(Ende.env.get("HOME")); // e.g. outputs "/home/alice"
console.log(Ende.env.get("MADE_UP_VAR")); // outputs undefined
Requires allow-env permission.
set
set(key: string, value: string): voidSet the value of an environment variable.
Ende.env.set("SOME_VAR", "Value");
Ende.env.get("SOME_VAR"); // outputs "Value"
Requires allow-env permission.
delete
delete(key: string): voidDelete the value of an environment variable.
Ende.env.set("SOME_VAR", "Value");
Ende.env.delete("SOME_VAR"); // outputs "undefined"
Requires allow-env permission.
has
has(key: string): booleanCheck whether an environment variable is present or not.
Ende.env.set("SOME_VAR", "Value");
Ende.env.has("SOME_VAR"); // outputs true
Requires allow-env permission.
toObject
toObject(): { [index: string]: string }Returns a snapshot of the environment variables at invocation as a simple object of keys and values.
Ende.env.set("TEST_VAR", "A");
const myEnv = Ende.env.toObject();
console.log(myEnv.SHELL);
Ende.env.set("TEST_VAR", "B");
console.log(myEnv.TEST_VAR); // outputs "A"
Requires allow-env permission.
Ende.env
variable · requires --allow-env
const Ende.env: EnvAn interface containing methods to interact with the process environment variables.