# processenv

> processenv parses environment variables.

Latest version **3.0.9** (published 2021-08-16) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install processenv
pnpm add processenv
yarn add processenv
bun add processenv
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.9 |
| Published | 2021-08-16 |
| First published | 2015-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | thenativeweb-admin, goloroden, yeldir, nhummel, dotkuro |
| Keywords | env, environment, parser, process |

## Links

- npm: https://www.npmjs.com/package/processenv
- Repository: https://github.com/thenativeweb/processenv
- Homepage: https://github.com/thenativeweb/processenv#readme
- Issues: https://github.com/thenativeweb/processenv/issues
- npm.io page: https://npm.io/package/processenv

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

- 3.0.9 (latest) — 2021-08-16
- 3.0.8 — 2021-06-10
- 3.0.7 — 2021-06-08
- 3.0.6 — 2021-06-08
- 3.0.5 — 2021-05-10
- 3.0.4 — 2021-03-25
- 3.0.3 — 2020-11-03
- 3.0.2 — 2020-04-30
- 3.0.1 — 2019-12-04
- 3.0.0 — 2019-11-14
- 2.0.1 — 2019-09-05
- 2.0.0 — 2019-08-28
- 1.1.0 — 2018-06-16
- 1.0.2 — 2018-06-14
- 1.0.1 — 2018-06-14
- … 3 more at https://npm.io/package/processenv/versions

## README

# processenv

processenv parses environment variables.

## Status

| Category         | Status                                                                                                                                           |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Version          | [![npm](https://img.shields.io/npm/v/processenv)](https://www.npmjs.com/package/processenv)                                                      |
| Dependencies     | ![David](https://img.shields.io/david/thenativeweb/processenv)                                                                                   |
| Dev dependencies | ![David](https://img.shields.io/david/dev/thenativeweb/processenv)                                                                               |
| Build            | ![GitHub Actions](https://github.com/thenativeweb/processenv/workflows/Release/badge.svg?branch=main) |
| License          | ![GitHub](https://img.shields.io/github/license/thenativeweb/processenv)                                                                         |

## Installation

```shell
$ npm install processenv
```

## Quick start

First you need to integrate processenv into your application:

```javascript
const { processenv } = require('processenv');
```

If you use TypeScript, use the following code instead:

```typescript
import { processenv } from 'processenv';
```

Then, to parse an environment variable, call the `processenv` function and provide the name of the environment variable you would like to parse:

```javascript
const port = processenv('PORT');
```

Please note that the value is automatically converted to the appropriate data type, e.g. a `number`. This also works for stringified JSON objects, in case you want to store complex configuration data inside an environment variable.

### Using default values

If you want to provide a default value, you may add it as a second parameter. This also works for booleans and all other types. If neither the environment variable nor the desired default value are set, `processenv` returns `undefined`:

```javascript
const port = processenv('PORT', 3000);
const user = processenv('USER', 'Jane Doe');
const isRoot = processenv('ROOT', true);
```

Alternatively, you may also provide a function which returns the default values. This is useful, e.g. if you want to lazily evaluate a value:

```javascript
const port = processenv('PORT', () => 3000);
```

If you want to use an asynchronous function, please note that you must `await` the call to `processenv`:

```javascript
const port = await processenv('PORT', async () => 3000);
```

#### Using the `??` operator

Instead of providing a second parameter, you may use the `??` operator to handle default values:

```javascript
const isRoot = processenv('ROOT') ?? true;
```

*Please note that this is only true if you are using the `??` operator. If you are using the old-style `||` operator instead, the previous line always returns `true`, no matter what the actual value of the `ROOT` environment variable is. To avoid this problem, either use the `??` operator or use the previously shown syntax using a second parameter to provide a default value.*

### Getting all environment variables

If you want to get all environment variables at once, omit the name and simply call `processenv`. The values will all be parsed, but you can not specify default values.

```javascript
const environmentVariables = processenv();
```

## Running quality assurance

To run quality assurance for this module use [roboter](https://www.npmjs.com/package/roboter):

```shell
$ npx roboter
```

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