GeezerVison is showing github.com — doc,test: specify and test CLI option precedence rules · nodejs/node@b75822d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/cli.md +6Lines changed: 6 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,11 @@ dashes (`-`) or underscores (`_`). |
34 | 34 |
|
35 | 35 | For example, `--pending-deprecation` is equivalent to `--pending_deprecation`. |
36 | 36 |
|
| 37 | +If an option that takes a single value, for example `--max-http-header-size`, |
| 38 | +is passed more than once, then the last passed value will be used. Options |
| 39 | +from the command line take precedence over options passed through the |
| 40 | +[`NODE_OPTIONS`][] environment variable. |
| 41 | + |
37 | 42 | ### `-` |
38 | 43 | <!-- YAML |
39 | 44 | added: v8.0.0 |
@@ -1554,6 +1559,7 @@ $ node --max-old-space-size=1536 index.js |
1554 | 1559 | [`Atomics.wait()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait |
1555 | 1560 | [`Buffer`]: buffer.html#buffer_class_buffer |
1556 | 1561 | [`SlowBuffer`]: buffer.html#buffer_class_slowbuffer |
| 1562 | +[`NODE_OPTIONS`]: #cli_node_options_options |
1557 | 1563 | [`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn |
1558 | 1564 | [`tls.DEFAULT_MAX_VERSION`]: tls.html#tls_tls_default_max_version |
1559 | 1565 | [`tls.DEFAULT_MIN_VERSION`]: tls.html#tls_tls_default_min_version |
|
Collapse file
Copy file name to clipboard +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const { spawnSync } = require('child_process'); |
| 5 | + |
| 6 | +// The last option on the command line takes precedence: |
| 7 | +assert.strictEqual(spawnSync(process.execPath, [ |
| 8 | + '--max-http-header-size=1234', |
| 9 | + '--max-http-header-size=5678', |
| 10 | + '-p', 'http.maxHeaderSize' |
| 11 | +], { |
| 12 | + encoding: 'utf8' |
| 13 | +}).stdout.trim(), '5678'); |
| 14 | + |
| 15 | +// The command line takes precedence over NODE_OPTIONS: |
| 16 | +assert.strictEqual(spawnSync(process.execPath, [ |
| 17 | + '--max-http-header-size=5678', |
| 18 | + '-p', 'http.maxHeaderSize' |
| 19 | +], { |
| 20 | + encoding: 'utf8', |
| 21 | + env: { ...process.env, NODE_OPTIONS: '--max-http-header-size=1234' } |
| 22 | +}).stdout.trim(), '5678'); |