Enforce either process or require("process") (n/prefer-global/process)
The process module is defined as a global variable.
js
process.log(process === require("process")) //→ trueIt will be readable if we use either process consistently.
📖 Rule Details
This rule enforces which process we should use.
Options
This rule has a string option.
json
{
"n/prefer-global/process": ["error", "always" | "never"]
}"always"(default) ... enforces to use the global variableprocessrather thanrequire("process")."never"... enforces to userequire("process")rather than the global variableprocess.
always
Examples of 👎 incorrect code for this rule:
js
/*eslint n/prefer-global/process: [error]*/
const process = require("process")
process.exit(0)Examples of 👍 correct code for this rule:
js
/*eslint n/prefer-global/process: [error]*/
process.exit(0)never
Examples of 👎 incorrect code for the "never" option:
js
/*eslint n/prefer-global/process: [error, never]*/
process.exit(0)Examples of 👍 correct code for the "never" option:
js
/*eslint n/prefer-global/process: [error, never]*/
const process = require("process")
process.exit(0)