Back to Biomejs

noProcessEnv

src/content/docs/linter/rules/no-process-env.mdx

latest3.4 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.9.1` - Diagnostic Category: [`lint/style/noProcessEnv`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`n/no-process-env`](https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/no-process-env.md)

How to configure

json
{
	"linter": {
		"rules": {
			"style": {
				"noProcessEnv": "error"
			}
		}
	}
}

Description

Disallow the use of process.env.

The process.env object in Node.js stores configuration settings. Using it directly throughout a project can cause problems:

  1. It's harder to maintain
  2. It can lead to conflicts in team development
  3. It complicates deployment across multiple servers

A better practice is to keep all settings in one configuration file and reference it throughout the project.

Examples

Invalid

js
if (process.env.NODE_ENV === 'development') {
  // ...
}
<pre class="language-text"><code class="language-text">code-block.js:1:5 <a href="https://biomejs.dev/linter/rules/no-process-env">lint/style/noProcessEnv</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Don't use </span><span style="color: lightgreen;"><strong>process.env</strong></span><span style="color: lightgreen;">.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>if (process.env.NODE&#95;ENV === 'development') &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> // ... <strong>3 │ </strong>&#125; <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Use a centralized configuration file instead for better maintainability and deployment consistency.</span> </code></pre>

Valid

js
const config = require('./config');
if (config.NODE_ENV === 'development') {
  // ...
}
</TabItem> </Tabs>