# envari

> A safer way to load .env files

Latest version **1.0.1** (published 2022-10-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install envari
pnpm add envari
yarn add envari
bun add envari
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-10-07 |
| First published | 2022-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Juan de Urtubey |
| Maintainers | jdeurt |
| Keywords | envari, .env, environment |

## Links

- npm: https://www.npmjs.com/package/envari
- Repository: https://github.com/jdeurt/envari
- Homepage: https://github.com/jdeurt/envari#readme
- Issues: https://github.com/jdeurt/envari/issues
- npm.io page: https://npm.io/package/envari

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-10-07
- 1.0.0 — 2022-10-07
- 0.2.0 — 2022-10-06

## README

# Envari

A safer way to load .env files

## Installation

```bash
npm i envari
```

or

```bash
yarn add envari
```

## Options

-   `properties`: The properties that should be present in the .env file
-   `missingPropertyBehavior`: The action that should be taken if a required property is missing
    -   `"THROW"` (default): Throw an error
    -   `"FALLBACK"`: Use an empty string for the property instead
-   `filePath`: The file path to the .env file (defaults to the .env file in the project root)

## Usage

```shell
# .env
SECRET_KEY="******"
```

```js
// env.js
import * as Envari from "envari";

export const env = Envari.load({
    properties: {
        SECRET_KEY: true,
    },
});
```

The result of calling `Envari.load` will be an object representation of your `.env` file.
Envari also automatically populates `process.env` with your `.env` values.

```js
// index.js
import { env } from "/env.js";

console.log(env.SECRET_KEY); // "******"
console.log(process.env.SECRET_KEY); // "******"
```

## Example with all options used

```js
import * as Envari from "envari";

const env = Envari.load({
    properties: {
        SECRET_KEY: true,
        SUPER_SECRET_KEY: true,
    },
    missingPropertyBehavior: "FALLBACK",
    filePath: "./some/path/to/.env",
});

console.log(env); // { SECRET_KEY: "******", SUPER_SECRET_KEY: "" }
```

## License

MIT © [Juan de Urtubey](https://jdeurt.xyz)

---
_Source: https://npm.io/package/envari · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
