close

no-process-env

Unreleased

Configuration

rslint.config.ts
import { defineConfig } from '@rslint/core';

export default defineConfig([
  {
    plugins: ['node'],
    rules: {
      'node/no-process-env': 'error',
    },
  },
]);

Rule details

Disallows process.env and process["env"] accesses. Keeping environment-dependent settings in a configuration module makes them easier to manage throughout a project.

Examples of incorrect code for this rule:

if (process.env.NODE_ENV === "development") {
  enableDebugging();
}

Examples of correct code for this rule:

const config = require("./config");

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

Options

allowedVariables is an array of environment variable names that may be accessed. It defaults to an empty array.

export default [
  {
    plugins: ["node"],
    rules: {
      "node/no-process-env": ["error", { allowedVariables: ["NODE_ENV"] }],
    },
  },
];

With this configuration, process.env.NODE_ENV and process["env"]["NODE_ENV"] are allowed. Reading process.env itself or accessing other variable names still reports an error. Computed variable names such as process.env[name] are not exempted.

This rule has no automatic fix or suggestions.

Original documentation