# class-config

> Package that creates and instance of the supplied Class, decorated with class-transform and class-validator decorators

Latest version **2.3.3** (published 2021-02-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install class-config
pnpm add class-config
yarn add class-config
bun add class-config
```

## 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 | 2.3.3 |
| Published | 2021-02-23 |
| First published | 2020-11-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Stefan Hariton |
| Maintainers | haritonstefan |
| Keywords | config, class-config, env |

## Links

- npm: https://www.npmjs.com/package/class-config
- Repository: https://github.com/haritonstefan/class-config
- Homepage: https://github.com/haritonstefan/class-config#readme
- Issues: https://github.com/haritonstefan/class-config/issues
- npm.io page: https://npm.io/package/class-config

## Dependencies (2)

- [class-validator](https://npm.io/package/class-validator.md) ^0.13.1
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.4.0

## 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

- 2.3.3 (latest) — 2021-02-23
- 2.3.2 — 2021-02-10
- 2.3.1 — 2021-02-10
- 2.3.0 — 2021-02-10
- 2.2.0 — 2021-02-10
- 2.1.4 — 2021-01-13
- 2.1.3 — 2021-01-13
- 2.1.2 — 2021-01-07
- 2.1.1 — 2021-01-07
- 2.1.0 — 2021-01-07
- 2.0.2 — 2020-11-30
- 2.0.1 — 2020-11-30
- 2.0.0 — 2020-11-30

## README

# class-config
A module to read and validate the environment in which it's invoked.
It uses [class-validator](https://github.com/typestack/class-validator) and
[class-transformer](https://github.com/typestack/class-validator)

## Example
```typescript
import { IsFQDN, IsIP, IsNotEmpty, IsNumber, IsString } from 'class-validator';
import { Expose, Type } from 'class-transformer';
import { loadSync } from './dist';

// assuming there are the following values in process.env
process.env.USER = 'ADMIN';
process.env.APP_PORT = '1234';
process.env.APP_HOST = '0.0.0.0';
process.env.APP_FQDN = 'host.domain.com'

class Config {
    @IsString() //  Checks the value is a string
    @IsNotEmpty() // Not empty
    @Expose({ name: 'USER' }) // Reading it from process.env.USER property
    public user: string;

    @IsNumber() // Checks that the value is a number, or a string represented number
    @Type(() => Number)
    @Expose({ name: 'APP_PORT' }) // Reading it from process.env.APP_PORT property
    public appPort: number;

    @IsIP() // Checks that the value is an IP
    @Expose({ name: 'APP_HOST' }) // Reading it from process.env.APP_HOST
    public appHost: string;

    @IsFQDN()
    @Expose({ name: 'APP_FQDN' })
    public appFQDN: string = 'host.domain.com'; // Setting a default value
}

const config = loadSync(Config); // there is also load, which is the asynchronous version of loadSync.
console.log(config instanceof Config) //true
console.log(config.user) // 'ADMIN'
console.log(config.appPort) // 1234
console.log(config.appHost) // '0.0.0.0'
console.log(config.appFQDN) // 'localhost'
```

You can use any decorators from [class-validator](https://github.com/typestack/class-validator) and
[class-transformer](https://github.com/typestack/class-validator) to enhance your config class.

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