# @shopify/with-env

> A utility for executing code under a specific `NODE_ENV`

Latest version **3.1.0** (published 2024-06-10) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install @shopify/with-env
pnpm add @shopify/with-env
yarn add @shopify/with-env
bun add @shopify/with-env
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2024-06-10 |
| First published | 2018-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.12.0 |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1681 |
| Author | Shopify Inc. |
| Maintainers | jaimie.rockburn, blittle, shopify-admin, maryharte, crisfmb, pmoloney89, netlohan, st999999, justin-irl, megswim, wcandillon, nathanpjf, shopify-dep, goodforonefare, lemonmade, vsumner, wizardlyhel, antoine.grant, tsov, andyw8-shopify, henrytao, hannachen, vividviolet, bpscott |

## Links

- npm: https://www.npmjs.com/package/@shopify/with-env
- Repository: https://github.com/Shopify/quilt
- Homepage: https://github.com/Shopify/quilt/blob/main/packages/with-env/README.md
- Issues: https://github.com/Shopify/quilt/issues
- npm.io page: https://npm.io/package/@shopify/with-env

## Recent versions

- 3.1.0 (latest) — 2024-06-10
- 2.0.6-export-beta.0 (next) — 2022-02-22
- 3.0.1 — 2022-08-24
- 3.0.0 — 2022-05-19
- 2.0.8 — 2022-03-09
- 2.0.7 — 2022-02-25
- 2.0.6 — 2022-02-01
- 2.0.4 — 2021-09-24
- 2.0.3 — 2021-08-24
- 2.0.2 — 2021-08-04
- 2.0.1 — 2021-08-04
- 2.0.0 — 2021-05-22
- 1.2.4 — 2021-04-13
- 1.2.3 — 2021-03-23
- 1.2.2 — 2021-03-04
- … 32 more at https://npm.io/package/@shopify/with-env/versions

## README

# `@shopify/with-env`

[![Build Status](https://github.com/Shopify/quilt/workflows/Node-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ANode-CI)
[![Build Status](https://github.com/Shopify/quilt/workflows/Ruby-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ARuby-CI)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/%40shopify%2Freact-shopify-app-route-propagator.svg)](https://badge.fury.io/js/%40shopify%2Freact-shopify-app-route-propagator)

A utility for executing code under a specific `NODE_ENV`.

## Installation

```bash
yarn add @shopify/with-env
```

Or, if you just need this for `test`s:

```bash
yarn add --dev @shopify/with-env
```

## Example Usage

In this example, we are testing some code using `Jest`. Note that, while `Jest` is not required to use `@shopify/with-env`, it is our recommended testing framework for node and javascript applications.

```ts
import withEnv from '@shopify/with-env';

it('does one thing in development', () => {
  withEnv('development', () => {
    // your code here
  });
});

it('does another thing in production', () => {
  withEnv('production', () => {
    // your code here
  });
});
```

It also allows to change (and reset) multiple environment variables at once.

```ts
import withEnv from '@shopify/with-env';

it('does one thing', () => {
  withEnv({MY_ENV_ONE: 'test', ANOTHER_ENV: 'test-2'}, () => {
    // your code here
  });
});
```

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