]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-process-env.md
upgrade to v7.0.0
[pve-eslint.git] / eslint / docs / rules / no-process-env.md
1 # Disallow process.env (no-process-env)
2
3 This rule was **deprecated** in ESLint v7.0.0. Please use the corresponding rule in [`eslint-plugin-node`](https://github.com/mysticatea/eslint-plugin-node).
4
5 The `process.env` object in Node.js is used to store deployment/configuration parameters. Littering it through out a project could lead to maintenance issues as it's another kind of global dependency. As such, it could lead to merge conflicts in a multi-user setup and deployment issues in a multi-server setup. Instead, one of the best practices is to define all those parameters in a single configuration/settings file which could be accessed throughout the project.
6
7
8 ## Rule Details
9
10 This rule is aimed at discouraging use of `process.env` to avoid global dependencies. As such, it will warn whenever `process.env` is used.
11
12 Examples of **incorrect** code for this rule:
13
14 ```js
15 /*eslint no-process-env: "error"*/
16
17 if(process.env.NODE_ENV === "development") {
18 //...
19 }
20 ```
21
22 Examples of **correct** code for this rule:
23
24 ```js
25 /*eslint no-process-env: "error"*/
26
27 var config = require("./config");
28
29 if(config.env === "development") {
30 //...
31 }
32 ```
33
34 ## When Not To Use It
35
36 If you prefer to use `process.env` throughout your project to retrieve values from environment variables, then you can safely disable this rule.
37
38 ## Further Reading
39
40 * [How to store Node.js deployment settings/configuration files? - Stack Overflow](https://stackoverflow.com/questions/5869216/how-to-store-node-js-deployment-settings-configuration-files)
41 * [Storing Node.js application config data - Ben Hall's blog](https://blog.benhall.me.uk/2012/02/storing-application-config-data-in/)