Skip to content

noProcessEnv

¥Summary

¥How to configure

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

¥Description

禁止使用 process.env

¥Disallow the use of process.env.

Node.js 中的 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

if (process.env.NODE_ENV === 'development') {
// ...
}
code-block.js:1:5 lint/style/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.

¥Valid

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

¥Related links