# env-rewrite

> Environment Variables Rewriter

Latest version **1.0.2** (published 2016-03-11) · MIT license · 0 weekly downloads

## Install

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

## 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.2 |
| Published | 2016-03-11 |
| First published | 2016-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Paweł Dziok |
| Maintainers | pdziok |
| Keywords | env, rewrite, environment, variable |

## Links

- npm: https://www.npmjs.com/package/env-rewrite
- Repository: https://github.com/pdziok/env-rewrite
- Homepage: https://github.com/pdziok/env-rewrite#readme
- Issues: https://github.com/pdziok/env-rewrite/issues
- npm.io page: https://npm.io/package/env-rewrite

## 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.2 (latest) — 2016-03-11

## README

# Environment Variables Rewriter

## Why

To break direct dependency between application and it's run environment

## Example

Running application on heroku and using add-ons causes adding Heroku Config Vars. 
Those Vars become Environment Variables within running dyno.

Heroku Vars are usually prefixed with add-on alias causing app to use
runtime configuration values.

Some of addons aliases cannot be changed.

### TL;DR

Heroku addon Elastic Cloud provides env `FOUNDELASTICSEARCH_URL`. 
Bonsai Elastic Search addon provides `BONSAI_URL`.
  
Changing one addon to another require application changes.

## Usage

Based on example given above:

Run your app with additional Environment Variable `REWRITE_ENV`

```shell
export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL
```

Inside your application rewrite envs before using any of them (preferably in the beginning of the entrypoint)

```javascript
require('env-rewrite').rewrite()
```

Now `ELASTICSEARCH_URL` env has value of `FOUNDELASTICSEARCH_URL`;

### Multiple rewrites

Separate rewrite directives with a comma (`,`). Example:

```shell
export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL,ES_URL:FOUNDELASTICSEARCH_URL
```

### Chaning

Values are rewritten one after another which enables rewrite chain.

```shell
export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL,ES_URL:ELASTICSEARCH_URL
```

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