Function load
- load(options?): Promise<Record<string, string>>
Parameters
- options: LoadOptions = {}
The options
Returns Promise<Record<string, string>>
The parsed environment variables
Example: Basic usage
// app.ts
import { load } from "@std/dotenv";
console.log(await load({ export: true })); // { GREETING: "hello world" }
console.log(Deno.env.get("GREETING")); // hello worldRun this with
deno run --allow-read --allow-env app.ts..env files support blank lines, comments, multi-line values and more. See Parsing Rules below for more detail.
Auto loading
Import the
load.tsmodule to auto-import from the.envfile and into the process environment.Example: Auto-loading
// app.ts
import "@std/dotenv/load";
console.log(Deno.env.get("GREETING")); // hello worldRun this with
deno run --allow-read --allow-env app.ts.Files
Dotenv supports a number of different files, all of which are optional. File names and paths are configurable.
File Purpose .env primary file for storing key-value environment entries Configuration
Loading environment files comes with a number of options passed into the
load()function, all of which are optional.Option Default Description envPath ./.env Path and filename of the .envfile. Use null to prevent the .env file from being loaded.export false When true, this will export all environment variables in the .envfile to the process environment (e.g. for use byDeno.env.get()) but only if they are not already set. If a variable is already in the process, the.envvalue is ignored.Example configuration
- options: LoadOptions = {}
Load environment variables from a
.envfile. Loaded variables are accessible in a configuration object returned by theload()function, as well as optionally exporting them to the process environment using theexportoption.Inspired by the node modules
dotenvanddotenv-expand.Note: The key needs to match the pattern /^[a-zA-Z_][a-zA-Z0-9_]*$/.
Basic usage
Then import the environment variables using the
loadfunction.