Skip to content
← Back to rules

node/no-process-env Restriction

What it does ​

Disallows use of process.env.

Why is this bad? ​

Directly reading process.env can lead to implicit runtime configuration, make code harder to test, and bypass configuration validation.

Examples ​

Examples of incorrect code for this rule:

js
if (process.env.NODE_ENV === "development") {
  // ...
}

Examples of correct code for this rule:

js
import config from "./config";

if (config.env === "development") {
  //...
}

Configuration ​

This rule accepts a configuration object with the following properties:

allowedVariables ​

type: string[]

default: []

Variable names which are allowed to be accessed on process.env.

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["node"],
  "rules": {
    "node/no-process-env": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["node"],
  rules: {
    "node/no-process-env": "error",
  },
});
bash
oxlint --deny node/no-process-env --node-plugin

Version ​

This rule was added in v1.23.0.

References ​