Skip to content

noProcessEnv

Diagnostic Category: lint/nursery/noProcessEnv

Since: v1.9.1

Sources:

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.

if (process.env.NODE_ENV === 'development') {
// ...
}
code-block.js:1:5 lint/nursery/noProcessEnv ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Don’t use process.env.

> 1 │ if (process.env.NODE_ENV === ‘development’) {
^^^^^^^^^^^
2 │ // …
3 │ }

Use a centralized configuration file instead for better maintainability and deployment consistency.

const config = require('./config');
if (config.NODE_ENV === 'development') {
// ...
}