# n/no-process-env

> Disallow `process.env`

When you read `process.env` all over the code, it's hard to list the variables the program needs, a misspelled name gives `undefined` without an error, and tests have to change the process's environment. Read the environment in one config file and import the values from there.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"n/no-process-env" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"n/no-process-env" = ["error", {
  allowedVariables = [], # list of strings
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
if (process.env.NODE_ENV === "development") {
  enableLogging();
}
```

Not reported:

{/* good */}
```js
import { config } from "./config";

if (config.env === "development") {
  enableLogging();
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowedVariables` | `[]` | Names of variables you can read from `process.env`. |

{/* good {"options": [{"allowedVariables": ["NODE_ENV"]}]} */}
```js
const isProduction = process.env.NODE_ENV === "production";
const mode = process.env["NODE_ENV"];
```

Other variables are still reported, and so is `process.env` by itself:

{/* bad {"options": [{"allowedVariables": ["NODE_ENV"]}], "count": 2} */}
```js
const port = process.env.PORT;
const { NODE_ENV } = process.env;
```

## When not to use it

Turn it off for the one file that reads the environment, and in scripts and small tools where a config file is more than you need.
