# express-env

> Safely expose your environment variables to dynamically fetch them in the frontend.

Latest version **1.0.4** (published 2021-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-env
pnpm add express-env
yarn add express-env
bun add express-env
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-11-22 |
| First published | 2019-05-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Leonardo Kewitz |
| Maintainers | kewitz |
| Keywords | env, environment, express, middleware, variables |

## Links

- npm: https://www.npmjs.com/package/express-env
- npm.io page: https://npm.io/package/express-env

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## 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.4 (latest) — 2021-11-22
- 1.0.3 — 2019-08-28
- 1.0.2 — 2019-05-20
- 1.0.1 — 2019-05-20
- 1.0.0 — 2019-05-20

## README

# Express-Env

Safely expose your environment variables to dynamically fetch them in the frontend.

```ts
import expressEnv from 'express-env'

app.use('/env', expressEnv())
```

```html
<!DOCTYPE html>
<html>
<head>
  <script src="./env"></script>
</head>
<body>
  <script>
    console.log(window.ENV)
  </script>
</body>
</html>
```

## Configurable Options

### Namespace
```ts
process.env = {
  'WILLEM': 'DAFOE',
  'MICHAEL': 'DOUGLAS',
}

app.use('/env', expressEnv({ namespace: 'window.LEAKY_ENVIRONMENT' }))
// GET /env: window.LEAKY_ENVIRONMENT = {"WILLEM":"DAFOE","MICHAEL":"DOUGLAS"}
```

### Black and Whitelisting

As an array of strings:
```ts
process.env = {
  'WILLEM': 'DAFOE',
  'MICHAEL': 'DOUGLAS',
}

app.use('/env', expressEnv({ whitelist: ['MICHAEL'] }))
// GET /env: window.ENV = {"MICHAEL":"DOUGLAS"}
```

As a function:
```ts
process.env = {
  'WILLEM': 'DAFOE',
  'MICHAEL': 'DOUGLAS',
}

app.use('/env', expressEnv({ blacklist: (value: string, key: string) => key.includes('CH') }))
// GET /env: window.ENV = {"WILLEM":"DAFOE"}
```

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