# nodeenv

> nodeenv enables tests to control Node.js environment variables.

Latest version **3.0.75** (published 2022-09-12) · MIT license · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.75 |
| Published | 2022-09-12 |
| First published | 2013-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 30.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | thenativeweb-admin, goloroden, yeldir, nhummel, dotkuro |
| Keywords | environment, nodeenv |

## Links

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

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) 18.7.16

## 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.75 (latest) — 2022-09-12
- 3.0.74 — 2022-02-07
- 3.0.73 — 2022-01-25
- 3.0.72 — 2022-01-09
- 3.0.71 — 2021-08-16
- 3.0.70 — 2021-08-16
- 3.0.69 — 2021-08-09
- 3.0.68 — 2021-08-02
- 3.0.67 — 2021-07-26
- 3.0.66 — 2021-07-19
- 3.0.65 — 2021-07-12
- 3.0.64 — 2021-07-05
- 3.0.63 — 2021-06-28
- 3.0.62 — 2021-06-15
- 3.0.61 — 2021-06-08
- … 75 more at https://npm.io/package/nodeenv/versions

## README

# nodeenv

nodeenv enables tests to control Node.js environment variables.

## Status

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

## Installation

```shell
$ npm install nodeenv
```

## Quick start

To use nodeenv you need to integrate it in your application.

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

If you use TypeScript, use the following code instead:

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

Then, to set environment variables, call the `nodeenv` function and provide an object whose keys are the environment variables' names and the values are their values. If you set a value to `undefined`, the environment variable will be removed.

```javascript
const restore = nodeenv({
  NODE_ENV: 'dev'
});

// ...

restore();
```

Once you call `restore`, the previous values of the environment variables will be restored.

### Setting a single variable

If you only want to set a single environment variable, you can specify its key and value without needing an object.

```javascript
const restore = nodeenv('NODE_ENV', 'dev');

// ...

restore();
```

### Setting NODE_ENV

If you only want to set the `NODE_ENV` environment variable you only need to provide the value and the `nodeenv` function will take care of the rest.

```javascript
nodeenv('dev');

// ...

restore();
```

## 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/nodeenv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
