# typed-env

> Typed environment variable parser

Latest version **2.0.0** (published 2025-05-25) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 45/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-05-25 |
| First published | 2020-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^14.18.0 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 21.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 23 |
| Maintainers | lukeuke, superchupu |
| Keywords | environment variables, env, parser, env parser, typescript, typed, config |

## Links

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

## 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.0.0 (latest) — 2025-05-25
- 1.0.1 — 2020-02-19
- 1.0.0 — 2020-02-19

## README

# typed-env

[![npm version](https://img.shields.io/npm/v/typed-env.svg?maxAge=3600)](https://npmjs.com/package/typed-env)
[![monthly downloads](https://img.shields.io/npm/dm/typed-env.svg?maxAge=3600)](https://npmjs.com/package/typed-env)

A typed environment variable parser with support for choices, custom parsers, and more.

## Usage

```ts
import { createEnv } from 'typed-env';

const env = createEnv({
  PORT: { type: 'number', default: 80 }
});

env.PORT; // number
```

## Features

- Strongly typed
- Supports [custom parsers](#parser)
- Supports optional environment variables
- Supports limiting the possible values (see [Choices](#choices))
- Supports passing custom environments (see [Options](#options))

### Choices

```ts
import { createEnv } from 'typed-env';

const env = createEnv({
  NODE_ENV: {
    type: 'string',
    choices: ['development', 'production']
  }
});

env.NODE_ENV; // 'development' | 'production'
```

### Parser

You can pass a `parser` function to return your own custom type

```ts
import { createEnv } from 'typed-env';

const env = createEnv({
  HOMEPAGE: { parser: url => new URL(url) }
});

env.HOMEPAGE; // URL
```

### Options

If you want to use a custom env, pass `env` in the `options` parameter, otherwise it will load from `process.env`

```ts
interface Options {
  env?: Record<string, string> | NodeJS.ProcessEnv;
}
```

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