# 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](https://envapt.materwelon.dev/docs/sources#the-sources-envapt-ships)

## Implements

- `FileCapableSource`

## Constructors

### Constructor

```ts
new FileSource(): FileSource;
```

#### Returns

`FileSource`

## Properties

| Property | Modifier | Type | Default value | Description |
| ------ | ------ | ------ | ------ | ------ |
|  `supportsFiles` | `readonly` | `true` | `true` | Always `true`. |

## Methods

### normalizeBaseDir()

```ts
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

| Parameter | Type |
| ------ | ------ |
| `value` | `string` \| `URL` |

#### Returns

`string`

#### Implementation of

```ts
FileCapableSource.normalizeBaseDir
```

***

### readFile()

```ts
readFile(path, encoding): string | undefined;
```

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

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `path` | `string` |
| `encoding` | `string` |

#### Returns

`string` \| `undefined`

#### Implementation of

```ts
FileCapableSource.readFile
```

***

### readVars()

```ts
readVars(): Record<string, string>;
```

Returns a copy of `process.env`.

#### Returns

`Record`\<`string`, `string`\>

#### Implementation of

```ts
FileCapableSource.readVars
```

***

### resolvePath()

```ts
resolvePath(baseDir, candidate): string;
```

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

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `baseDir` | `string` |
| `candidate` | `string` |

#### Returns

`string`

#### Implementation of

```ts
FileCapableSource.resolvePath
```

***

### writeVars()

```ts
writeVars(vars): void;
```

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

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `vars` | `Record`\<`string`, `string`\> |

#### Returns

`void`

#### Implementation of

```ts
FileCapableSource.writeVars
```