noProcessEnv
Diagnostic Category: lint/nursery/noProcessEnv
Since: v1.9.1
Sources:
- Same as:
n/no-process-env
Description
Section titled DescriptionDisallow the use of process.env
.
The process.env
object in Node.js stores configuration settings. Using it directly throughout a project can cause problems:
- It’s harder to maintain
- It can lead to conflicts in team development
- 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
Section titled ExamplesInvalid
Section titled Invalidif (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.
Valid
Section titled Validconst config = require('./config');if (config.NODE_ENV === 'development') { // ...}
How to configure
Section titled How to configure{ "linter": { "rules": { "nursery": { "noProcessEnv": "error" } } }}