v9.1.0
envaptClasses

FileSource

Default environment source on Node, Bun, and Deno: a snapshot of process.env. Because supportsFiles is true, envapt also loads the .env cascade and resolves baseDir. A key set in process.env wins over the same key in a file unless envFileOptions.override is true. Envapter.syncProcessEnv can copy loaded keys back to process.env.

See

https://envapt.materwelon.dev/docs/sources#the-sources-envapt-ships

Implements

  • FileCapableSource

Constructors

Constructor

new FileSource(): FileSource;

Returns

FileSource

Properties

PropertyModifierTypeDefault valueDescription
supportsFilesreadonlytruetrueAlways true.

Methods

normalizeBaseDir()

normalizeBaseDir(value): string;

Resolves a directory path or a module / file: URL to an absolute directory. A file: URL resolves to its containing directory. A plain path (import.meta.dirname) is taken as the directory itself.

Parameters

ParameterType
valuestring | URL

Returns

string

Implementation of

FileCapableSource.normalizeBaseDir

readFile()

readFile(path, encoding): string | undefined;

Reads a file with fs.readFileSync, or undefined when it is missing or unreadable.

Parameters

ParameterType
pathstring
encodingstring

Returns

string | undefined

Implementation of

FileCapableSource.readFile

readVars()

readVars(): Record<string, string>;

Returns a copy of process.env.

Returns

Record<string, string>

Implementation of

FileCapableSource.readVars

resolvePath()

resolvePath(baseDir, candidate): string;

Joins a relative .env path onto baseDir. Absolute paths pass through unchanged.

Parameters

ParameterType
baseDirstring
candidatestring

Returns

string

Implementation of

FileCapableSource.resolvePath

writeVars()

writeVars(vars): void;

Writes each key to process.env. Envapter.syncProcessEnv calls it.

Parameters

ParameterType
varsRecord<string, string>

Returns

void

Implementation of

FileCapableSource.writeVars

On this page