# env-decorator

> Decorator for environment based configurations

Latest version **1.1.1** (published 2022-10-25) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-10-25 |
| First published | 2018-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 8.0.0 |
| Dependencies | 1 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Jean-Baptiste Pionnier |
| Maintainers | jbpionnier |
| Keywords | config, configuration, env, environment, decorator, settings, typescript |

## Links

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

## Dependencies (1)

- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## 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.1.1 (latest) — 2022-10-25
- 1.1.0 — 2022-05-16
- 1.0.0 — 2019-07-12
- 0.1.0 — 2018-12-21
- 0.0.2 — 2018-08-30
- 0.0.1 — 2018-08-28

## README

# Env Decorator

[![npm version](https://badge.fury.io/js/env-decorator.svg)](https://badge.fury.io/js/env-decorator)
[![Build Status](https://travis-ci.org/jbpionnier/env-decorator.svg?branch=master)](https://travis-ci.org/jbpionnier/env-decorator)
[![npm](https://img.shields.io/npm/dm/env-decorator.svg)](https://npm-stat.com/charts.html?package=env-decorator)

Type your environment variables with decorators for environment based configurations

## :package: Installation

To install the module from npm:

```
npm install --save env-decorator
```

## :blue_book: Usage

**Config class**

```js
import { loadConfig, Env } from 'env-decorator'

export class Config {
	
  @Env({ required: true })
  NODE_ENV: string

  // Use the 'number' or 'boolean' type
  @Env({ type: 'number' })
  PORT: number

  @Env()
  ELASTICSEARCH_URL: string

  @Env('APP_DEBUG', { type: 'boolean' })
  DEBUG: boolean = true

  @Env([ 'MONGO_URL', 'MONGO_URI', 'MONGODB_ADDON_URI' ])
  MONGO_URL: string
}

export const config = loadConfig(Config)
```

**Import**

```js
import * as elasticsearch from 'elasticsearch'
import { config } from './config'

const client = new elasticsearch.Client({
  host: config.ELASTICSEARCH_URL
})
```

## :memo: License

[MIT](http://opensource.org/licenses/MIT)

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