# read-env-value

> Read env with default value

Latest version **2.0.2** (published 2025-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install read-env-value
pnpm add read-env-value
yarn add read-env-value
bun add read-env-value
```

## 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.2 |
| Published | 2025-08-08 |
| First published | 2025-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >= 22.18.0 |
| Dependencies | 0 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | fengmk2 |
| Maintainers | fengmk2 |
| Keywords | env, environment |

## Links

- npm: https://www.npmjs.com/package/read-env-value
- Repository: https://github.com/node-modules/read-env-value
- Homepage: https://github.com/node-modules/read-env-value#readme
- Issues: https://github.com/node-modules/read-env-value/issues
- npm.io page: https://npm.io/package/read-env-value

## 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.2 (latest) — 2025-08-08
- 2.0.1 — 2025-07-31
- 2.0.0 — 2025-07-30
- 1.1.0 — 2025-05-10
- 1.0.1 — 2025-04-24
- 1.0.0 — 2025-02-10
- 0.0.0 — 2025-02-10

## README

# read-env-value

[![NPM Version](https://img.shields.io/npm/v/read-env-value)](https://www.npmjs.com/package/read-env-value)
[![NPM Downloads](https://img.shields.io/npm/dm/read-env-value)](https://www.npmjs.com/package/read-env-value)
[![NPM License](https://img.shields.io/npm/l/read-env-value)](https://github.com/node-modules/read-env-value/blob/master/LICENSE)
[![JSR](https://jsr.io/badges/@nm/read-env-value)](https://jsr.io/@nm/read-env-value)
[![JSR Score](https://jsr.io/badges/@nm/read-env-value/score)](https://jsr.io/@nm/read-env-value)
[![codecov](https://codecov.io/gh/node-modules/read-env-value/branch/master/graph/badge.svg)](https://codecov.io/gh/node-modules/read-env-value)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/node-modules/read-env-value/ci.yml?branch=master)](https://github.com/node-modules/read-env-value/actions/workflows/ci.yml?query=branch%3Amaster)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/node-modules/read-env-value)

Read env with default value

## Usage

```ts
import { env } from 'read-env-value';

// read env 'NODE_ENV' with default value 'development'
const value = env('NODE_ENV', 'string', 'development');
```

## API

### env(key: string, type: 'string' | 'number' | 'boolean', defaultValue?: string | number | boolean)

#### Parameters

- `key`: The environment variable key to read.
- `type`: The type of the value to be returned.
- `defaultValue`: The default value to return if the environment variable is not set.

#### Returns

- The value of the environment variable.

#### Example

```ts
import { env } from 'read-env-value';

const value = env('NODE_ENV', 'string', 'development');
```

## License

[MIT](./LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=node-modules/read-env-value)](https://github.com/node-modules/read-env-value/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).

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