forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.md
2698 lines (2013 loc) · 72.8 KB
/
cli.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Command-line API
<!--introduced_in=v5.9.1-->
<!--type=misc-->
Node.js comes with a variety of CLI options. These options expose built-in
debugging, multiple ways to execute scripts, and other helpful runtime options.
To view this documentation as a manual page in a terminal, run `man node`.
## Synopsis
`node [options] [V8 options] [<program-entry-point> | -e "script" | -] [--] [arguments]`
`node inspect [<program-entry-point> | -e "script" | <host>:<port>] …`
`node --v8-options`
Execute without arguments to start the [REPL][].
For more info about `node inspect`, see the [debugger][] documentation.
## Program entry point
The program entry point is a specifier-like string. If the string is not an
absolute path, it's resolved as a relative path from the current working
directory. That path is then resolved by [CommonJS][] module loader. If no
corresponding file is found, an error is thrown.
If a file is found, its path will be passed to the [ECMAScript module loader][]
under any of the following conditions:
* The program was started with a command-line flag that forces the entry
point to be loaded with ECMAScript module loader.
* The file has an `.mjs` extension.
* The file does not have a `.cjs` extension, and the nearest parent
`package.json` file contains a top-level [`"type"`][] field with a value of
`"module"`.
Otherwise, the file is loaded using the CommonJS module loader. See
[Modules loaders][] for more details.
### ECMAScript modules loader entry point caveat
When loading [ECMAScript module loader][] loads the program entry point, the `node`
command will only accept as input only files with `.js`, `.mjs`, or `.cjs`
extensions; and with `.wasm` extensions when
[`--experimental-wasm-modules`][] is enabled.
## Options
<!-- YAML
changes:
- version: v10.12.0
pr-url: https://github.com/nodejs/node/pull/23020
description: Underscores instead of dashes are now allowed for
Node.js options as well, in addition to V8 options.
-->
All options, including V8 options, allow words to be separated by both
dashes (`-`) or underscores (`_`). For example, `--pending-deprecation` is
equivalent to `--pending_deprecation`.
If an option that takes a single value (such as `--max-http-header-size`) is
passed more than once, then the last passed value is used. Options from the
command line take precedence over options passed through the [`NODE_OPTIONS`][]
environment variable.
### `-`
<!-- YAML
added: v8.0.0
-->
Alias for stdin. Analogous to the use of `-` in other command-line utilities,
meaning that the script is read from stdin, and the rest of the options
are passed to that script.
### `--`
<!-- YAML
added: v6.11.0
-->
Indicate the end of node options. Pass the rest of the arguments to the script.
If no script filename or eval/print script is supplied prior to this, then
the next argument is used as a script filename.
### `--abort-on-uncaught-exception`
<!-- YAML
added: v0.10.8
-->
Aborting instead of exiting causes a core file to be generated for post-mortem
analysis using a debugger (such as `lldb`, `gdb`, and `mdb`).
If this flag is passed, the behavior can still be set to not abort through
[`process.setUncaughtExceptionCaptureCallback()`][] (and through usage of the
`node:domain` module that uses it).
### `--allow-child-process`
<!-- YAML
added: v20.0.0
-->
> Stability: 1 - Experimental
When using the [Permission Model][], the process will not be able to spawn any
child process by default.
Attempts to do so will throw an `ERR_ACCESS_DENIED` unless the
user explicitly passes the `--allow-child-process` flag when starting Node.js.
Example:
```js
const childProcess = require('node:child_process');
// Attempt to bypass the permission
childProcess.spawn('node', ['-e', 'require("fs").writeFileSync("/new-file", "example")']);
```
```console
$ node --experimental-permission --allow-fs-read=* index.js
node:internal/child_process:388
const err = this._handle.spawn(options);
^
Error: Access to this API has been restricted
at ChildProcess.spawn (node:internal/child_process:388:28)
at Object.spawn (node:child_process:723:9)
at Object.<anonymous> (/home/index.js:3:14)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)
at Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'ChildProcess'
}
```
### `--allow-fs-read`
<!-- YAML
added: v20.0.0
-->
> Stability: 1 - Experimental
This flag configures file system read permissions using
the [Permission Model][].
The valid arguments for the `--allow-fs-read` flag are:
* `*` - To allow all `FileSystemRead` operations.
* Paths delimited by comma (`,`) to allow only matching `FileSystemRead`
operations.
Examples can be found in the [File System Permissions][] documentation.
Relative paths are NOT yet supported by the CLI flag.
The initializer module also needs to be allowed. Consider the following example:
```console
$ node --experimental-permission t.js
node:internal/modules/cjs/loader:162
const result = internalModuleStat(filename);
^
Error: Access to this API has been restricted
at stat (node:internal/modules/cjs/loader:162:18)
at Module._findPath (node:internal/modules/cjs/loader:640:16)
at resolveMainPath (node:internal/modules/run_main:15:25)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:53:24)
at node:internal/main/run_main_module:23:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'FileSystemRead',
resource: '/Users/rafaelgss/repos/os/node/t.js'
}
```
The process needs to have access to the `index.js` module:
```bash
node --experimental-permission --allow-fs-read=/path/to/index.js index.js
```
### `--allow-fs-write`
<!-- YAML
added: v20.0.0
-->
> Stability: 1 - Experimental
This flag configures file system write permissions using
the [Permission Model][].
The valid arguments for the `--allow-fs-write` flag are:
* `*` - To allow all `FileSystemWrite` operations.
* Paths delimited by comma (`,`) to allow only matching `FileSystemWrite`
operations.
Examples can be found in the [File System Permissions][] documentation.
Relative paths are NOT supported through the CLI flag.
### `--allow-worker`
<!-- YAML
added: v20.0.0
-->
> Stability: 1 - Experimental
When using the [Permission Model][], the process will not be able to create any
worker threads by default.
For security reasons, the call will throw an `ERR_ACCESS_DENIED` unless the
user explicitly pass the flag `--allow-worker` in the main Node.js process.
Example:
```js
const { Worker } = require('node:worker_threads');
// Attempt to bypass the permission
new Worker(__filename);
```
```console
$ node --experimental-permission --allow-fs-read=* index.js
node:internal/worker:188
this[kHandle] = new WorkerImpl(url,
^
Error: Access to this API has been restricted
at new Worker (node:internal/worker:188:21)
at Object.<anonymous> (/home/index.js.js:3:1)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)
at Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'WorkerThreads'
}
```
### `--build-snapshot`
<!-- YAML
added: v18.8.0
-->
> Stability: 1 - Experimental
Generates a snapshot blob when the process exits and writes it to
disk, which can be loaded later with `--snapshot-blob`.
When building the snapshot, if `--snapshot-blob` is not specified,
the generated blob will be written, by default, to `snapshot.blob`
in the current working directory. Otherwise it will be written to
the path specified by `--snapshot-blob`.
```console
$ echo "globalThis.foo = 'I am from the snapshot'" > snapshot.js
# Run snapshot.js to initialize the application and snapshot the
# state of it into snapshot.blob.
$ node --snapshot-blob snapshot.blob --build-snapshot snapshot.js
$ echo "console.log(globalThis.foo)" > index.js
# Load the generated snapshot and start the application from index.js.
$ node --snapshot-blob snapshot.blob index.js
I am from the snapshot
```
The [`v8.startupSnapshot` API][] can be used to specify an entry point at
snapshot building time, thus avoiding the need of an additional entry
script at deserialization time:
```console
$ echo "require('v8').startupSnapshot.setDeserializeMainFunction(() => console.log('I am from the snapshot'))" > snapshot.js
$ node --snapshot-blob snapshot.blob --build-snapshot snapshot.js
$ node --snapshot-blob snapshot.blob
I am from the snapshot
```
For more information, check out the [`v8.startupSnapshot` API][] documentation.
Currently the support for run-time snapshot is experimental in that:
1. User-land modules are not yet supported in the snapshot, so only
one single file can be snapshotted. Users can bundle their applications
into a single script with their bundler of choice before building
a snapshot, however.
2. Only a subset of the built-in modules work in the snapshot, though the
Node.js core test suite checks that a few fairly complex applications
can be snapshotted. Support for more modules are being added. If any
crashes or buggy behaviors occur when building a snapshot, please file
a report in the [Node.js issue tracker][] and link to it in the
[tracking issue for user-land snapshots][].
### `--completion-bash`
<!-- YAML
added: v10.12.0
-->
Print source-able bash completion script for Node.js.
```bash
node --completion-bash > node_bash_completion
source node_bash_completion
```
### `-C condition`, `--conditions=condition`
<!-- YAML
added:
- v14.9.0
- v12.19.0
-->
> Stability: 1 - Experimental
Enable experimental support for custom [conditional exports][] resolution
conditions.
Any number of custom string condition names are permitted.
The default Node.js conditions of `"node"`, `"default"`, `"import"`, and
`"require"` will always apply as defined.
For example, to run a module with "development" resolutions:
```bash
node -C development app.js
```
### `--cpu-prof`
<!-- YAML
added: v12.0.0
-->
> Stability: 1 - Experimental
Starts the V8 CPU profiler on start up, and writes the CPU profile to disk
before exit.
If `--cpu-prof-dir` is not specified, the generated profile is placed
in the current working directory.
If `--cpu-prof-name` is not specified, the generated profile is
named `CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile`.
```console
$ node --cpu-prof index.js
$ ls *.cpuprofile
CPU.20190409.202950.15293.0.0.cpuprofile
```
### `--cpu-prof-dir`
<!-- YAML
added: v12.0.0
-->
> Stability: 1 - Experimental
Specify the directory where the CPU profiles generated by `--cpu-prof` will
be placed.
The default value is controlled by the
[`--diagnostic-dir`][] command-line option.
### `--cpu-prof-interval`
<!-- YAML
added: v12.2.0
-->
> Stability: 1 - Experimental
Specify the sampling interval in microseconds for the CPU profiles generated
by `--cpu-prof`. The default is 1000 microseconds.
### `--cpu-prof-name`
<!-- YAML
added: v12.0.0
-->
> Stability: 1 - Experimental
Specify the file name of the CPU profile generated by `--cpu-prof`.
### `--diagnostic-dir=directory`
Set the directory to which all diagnostic output files are written.
Defaults to current working directory.
Affects the default output directory of:
* [`--cpu-prof-dir`][]
* [`--heap-prof-dir`][]
* [`--redirect-warnings`][]
### `--disable-proto=mode`
<!-- YAML
added:
- v13.12.0
- v12.17.0
-->
Disable the `Object.prototype.__proto__` property. If `mode` is `delete`, the
property is removed entirely. If `mode` is `throw`, accesses to the
property throw an exception with the code `ERR_PROTO_ACCESS`.
### `--disallow-code-generation-from-strings`
<!-- YAML
added: v9.8.0
-->
Make built-in language features like `eval` and `new Function` that generate
code from strings throw an exception instead. This does not affect the Node.js
`node:vm` module.
### `--dns-result-order=order`
<!-- YAML
added:
- v16.4.0
- v14.18.0
changes:
- version: v17.0.0
pr-url: https://github.com/nodejs/node/pull/39987
description: Changed default value to `verbatim`.
-->
Set the default value of `verbatim` in [`dns.lookup()`][] and
[`dnsPromises.lookup()`][]. The value could be:
* `ipv4first`: sets default `verbatim` `false`.
* `verbatim`: sets default `verbatim` `true`.
The default is `verbatim` and [`dns.setDefaultResultOrder()`][] have higher
priority than `--dns-result-order`.
### `--enable-fips`
<!-- YAML
added: v6.0.0
-->
Enable FIPS-compliant crypto at startup. (Requires Node.js to be built
against FIPS-compatible OpenSSL.)
### `--no-network-family-autoselection`
<!-- YAML
added: v19.4.0
changes:
- version: v20.0.0
pr-url: https://github.com/nodejs/node/pull/46790
description: The flag was renamed from `--no-enable-network-family-autoselection`
to `--no-network-family-autoselection`. The old name can still work as
an alias.
-->
Disables the family autoselection algorithm unless connection options explicitly
enables it.
### `--enable-source-maps`
<!-- YAML
added: v12.12.0
changes:
- version:
- v15.11.0
- v14.18.0
pr-url: https://github.com/nodejs/node/pull/37362
description: This API is no longer experimental.
-->
Enable [Source Map v3][Source Map] support for stack traces.
When using a transpiler, such as TypeScript, stack traces thrown by an
application reference the transpiled code, not the original source position.
`--enable-source-maps` enables caching of Source Maps and makes a best
effort to report stack traces relative to the original source file.
Overriding `Error.prepareStackTrace` prevents `--enable-source-maps` from
modifying the stack trace.
Note, enabling source maps can introduce latency to your application
when `Error.stack` is accessed. If you access `Error.stack` frequently
in your application, take into account the performance implications
of `--enable-source-maps`.
### `--experimental-import-meta-resolve`
<!-- YAML
added:
- v13.9.0
- v12.16.2
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/49028
description: synchronous import.meta.resolve made available by default, with
the flag retained for enabling the experimental second argument
as previously supported.
-->
Enable experimental `import.meta.resolve()` parent URL support, which allows
passing a second `parentURL` argument for contextual resolution.
Previously gated the entire `import.meta.resolve` feature.
### `--experimental-loader=module`
<!-- YAML
added: v8.8.0
changes:
- version: v12.11.1
pr-url: https://github.com/nodejs/node/pull/29752
description: This flag was renamed from `--loader` to
`--experimental-loader`.
-->
Specify the `module` of a custom experimental [ECMAScript module loader][].
`module` may be any string accepted as an [`import` specifier][].
### `--experimental-network-imports`
<!-- YAML
added:
- v17.6.0
- v16.15.0
-->
> Stability: 1 - Experimental
Enable experimental support for the `https:` protocol in `import` specifiers.
### `--experimental-permission`
<!-- YAML
added: v20.0.0
-->
> Stability: 1 - Experimental
Enable the Permission Model for current process. When enabled, the
following permissions are restricted:
* File System - manageable through
[`--allow-fs-read`][], [`--allow-fs-write`][] flags
* Child Process - manageable through [`--allow-child-process`][] flag
* Worker Threads - manageable through [`--allow-worker`][] flag
### `--experimental-policy`
<!-- YAML
added: v11.8.0
-->
Use the specified file as a security policy.
### `--no-experimental-fetch`
<!-- YAML
added: v18.0.0
-->
Disable experimental support for the [Fetch API][].
### `--no-experimental-global-webcrypto`
<!-- YAML
added: v19.0.0
-->
Disable exposition of [Web Crypto API][] on the global scope.
### `--no-experimental-global-customevent`
<!-- YAML
added: v19.0.0
-->
Disable exposition of [CustomEvent Web API][] on the global scope.
### `--no-experimental-repl-await`
<!-- YAML
added: v16.6.0
-->
Use this flag to disable top-level await in REPL.
### `--experimental-sea-config`
<!-- YAML
added: v20.0.0
-->
> Stability: 1 - Experimental
Use this flag to generate a blob that can be injected into the Node.js
binary to produce a [single executable application][]. See the documentation
about [this configuration][`--experimental-sea-config`] for details.
### `--experimental-shadow-realm`
<!-- YAML
added:
- v19.0.0
- v18.13.0
-->
Use this flag to enable [ShadowRealm][] support.
### `--experimental-test-coverage`
<!-- YAML
added:
- v19.7.0
- v18.15.0
changes:
- version:
- v20.1.0
- v18.17.0
pr-url: https://github.com/nodejs/node/pull/47686
description: This option can be used with `--test`.
-->
When used in conjunction with the `node:test` module, a code coverage report is
generated as part of the test runner output. If no tests are run, a coverage
report is not generated. See the documentation on
[collecting code coverage from tests][] for more details.
### `--experimental-vm-modules`
<!-- YAML
added: v9.6.0
-->
Enable experimental ES Module support in the `node:vm` module.
### `--experimental-wasi-unstable-preview1`
<!-- YAML
added:
- v13.3.0
- v12.16.0
changes:
- version:
- v20.0.0
- v18.17.0
pr-url: https://github.com/nodejs/node/pull/47286
description: This option is no longer required as WASI is
enabled by default, but can still be passed.
- version: v13.6.0
pr-url: https://github.com/nodejs/node/pull/30980
description: changed from `--experimental-wasi-unstable-preview0` to
`--experimental-wasi-unstable-preview1`.
-->
Enable experimental WebAssembly System Interface (WASI) support.
### `--experimental-wasm-modules`
<!-- YAML
added: v12.3.0
-->
Enable experimental WebAssembly module support.
### `--force-context-aware`
<!-- YAML
added: v12.12.0
-->
Disable loading native addons that are not [context-aware][].
### `--force-fips`
<!-- YAML
added: v6.0.0
-->
Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.)
(Same requirements as `--enable-fips`.)
### `--frozen-intrinsics`
<!-- YAML
added: v11.12.0
-->
> Stability: 1 - Experimental
Enable experimental frozen intrinsics like `Array` and `Object`.
Only the root context is supported. There is no guarantee that
`globalThis.Array` is indeed the default intrinsic reference. Code may break
under this flag.
To allow polyfills to be added,
[`--require`][] and [`--import`][] both run before freezing intrinsics.
### `--force-node-api-uncaught-exceptions-policy`
<!-- YAML
added:
- v18.3.0
- v16.17.0
-->
Enforces `uncaughtException` event on Node-API asynchronous callbacks.
To prevent from an existing add-on from crashing the process, this flag is not
enabled by default. In the future, this flag will be enabled by default to
enforce the correct behavior.
### `--heapsnapshot-near-heap-limit=max_count`
<!-- YAML
added:
- v15.1.0
- v14.18.0
-->
> Stability: 1 - Experimental
Writes a V8 heap snapshot to disk when the V8 heap usage is approaching the
heap limit. `count` should be a non-negative integer (in which case
Node.js will write no more than `max_count` snapshots to disk).
When generating snapshots, garbage collection may be triggered and bring
the heap usage down. Therefore multiple snapshots may be written to disk
before the Node.js instance finally runs out of memory. These heap snapshots
can be compared to determine what objects are being allocated during the
time consecutive snapshots are taken. It's not guaranteed that Node.js will
write exactly `max_count` snapshots to disk, but it will try
its best to generate at least one and up to `max_count` snapshots before the
Node.js instance runs out of memory when `max_count` is greater than `0`.
Generating V8 snapshots takes time and memory (both memory managed by the
V8 heap and native memory outside the V8 heap). The bigger the heap is,
the more resources it needs. Node.js will adjust the V8 heap to accommodate
the additional V8 heap memory overhead, and try its best to avoid using up
all the memory available to the process. When the process uses
more memory than the system deems appropriate, the process may be terminated
abruptly by the system, depending on the system configuration.
```console
$ node --max-old-space-size=100 --heapsnapshot-near-heap-limit=3 index.js
Wrote snapshot to Heap.20200430.100036.49580.0.001.heapsnapshot
Wrote snapshot to Heap.20200430.100037.49580.0.002.heapsnapshot
Wrote snapshot to Heap.20200430.100038.49580.0.003.heapsnapshot
<--- Last few GCs --->
[49580:0x110000000] 4826 ms: Mark-sweep 130.6 (147.8) -> 130.5 (147.8) MB, 27.4 / 0.0 ms (average mu = 0.126, current mu = 0.034) allocation failure scavenge might not succeed
[49580:0x110000000] 4845 ms: Mark-sweep 130.6 (147.8) -> 130.6 (147.8) MB, 18.8 / 0.0 ms (average mu = 0.088, current mu = 0.031) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
....
```
### `--heapsnapshot-signal=signal`
<!-- YAML
added: v12.0.0
-->
Enables a signal handler that causes the Node.js process to write a heap dump
when the specified signal is received. `signal` must be a valid signal name.
Disabled by default.
```console
$ node --heapsnapshot-signal=SIGUSR2 index.js &
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
node 1 5.5 6.1 787252 247004 ? Ssl 16:43 0:02 node --heapsnapshot-signal=SIGUSR2 index.js
$ kill -USR2 1
$ ls
Heap.20190718.133405.15554.0.001.heapsnapshot
```
### `--heap-prof`
<!-- YAML
added: v12.4.0
-->
> Stability: 1 - Experimental
Starts the V8 heap profiler on start up, and writes the heap profile to disk
before exit.
If `--heap-prof-dir` is not specified, the generated profile is placed
in the current working directory.
If `--heap-prof-name` is not specified, the generated profile is
named `Heap.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.heapprofile`.
```console
$ node --heap-prof index.js
$ ls *.heapprofile
Heap.20190409.202950.15293.0.001.heapprofile
```
### `--heap-prof-dir`
<!-- YAML
added: v12.4.0
-->
> Stability: 1 - Experimental
Specify the directory where the heap profiles generated by `--heap-prof` will
be placed.
The default value is controlled by the
[`--diagnostic-dir`][] command-line option.
### `--heap-prof-interval`
<!-- YAML
added: v12.4.0
-->
> Stability: 1 - Experimental
Specify the average sampling interval in bytes for the heap profiles generated
by `--heap-prof`. The default is 512 \* 1024 bytes.
### `--heap-prof-name`
<!-- YAML
added: v12.4.0
-->
> Stability: 1 - Experimental
Specify the file name of the heap profile generated by `--heap-prof`.
### `--icu-data-dir=file`
<!-- YAML
added: v0.11.15
-->
Specify ICU data load path. (Overrides `NODE_ICU_DATA`.)
### `--import=module`
<!-- YAML
added: v19.0.0
-->
> Stability: 1 - Experimental
Preload the specified module at startup.
Follows [ECMAScript module][] resolution rules.
Use [`--require`][] to load a [CommonJS module][].
Modules preloaded with `--require` will run before modules preloaded with `--import`.
### `--input-type=type`
<!-- YAML
added: v12.0.0
-->
This configures Node.js to interpret string input as CommonJS or as an ES
module. String input is input via `--eval`, `--print`, or `STDIN`.
Valid values are `"commonjs"` and `"module"`. The default is `"commonjs"`.
The REPL does not support this option.
### `--inspect-brk[=[host:]port]`
<!-- YAML
added: v7.6.0
-->
Activate inspector on `host:port` and break at start of user script.
Default `host:port` is `127.0.0.1:9229`.
### `--inspect-port=[host:]port`
<!-- YAML
added: v7.6.0
-->
Set the `host:port` to be used when the inspector is activated.
Useful when activating the inspector by sending the `SIGUSR1` signal.
Default host is `127.0.0.1`.
See the [security warning][] below regarding the `host`
parameter usage.
### `--inspect[=[host:]port]`
<!-- YAML
added: v6.3.0
-->
Activate inspector on `host:port`. Default is `127.0.0.1:9229`.
V8 inspector integration allows tools such as Chrome DevTools and IDEs to debug
and profile Node.js instances. The tools attach to Node.js instances via a
tcp port and communicate using the [Chrome DevTools Protocol][].
<!-- Anchor to make sure old links find a target -->
<a id="inspector_security"></a>
#### Warning: binding inspector to a public IP:port combination is insecure
Binding the inspector to a public IP (including `0.0.0.0`) with an open port is
insecure, as it allows external hosts to connect to the inspector and perform
a [remote code execution][] attack.
If specifying a host, make sure that either:
* The host is not accessible from public networks.
* A firewall disallows unwanted connections on the port.
**More specifically, `--inspect=0.0.0.0` is insecure if the port (`9229` by
default) is not firewall-protected.**
See the [debugging security implications][] section for more information.
### `--inspect-publish-uid=stderr,http`
Specify ways of the inspector web socket url exposure.
By default inspector websocket url is available in stderr and under `/json/list`
endpoint on `http://host:port/json/list`.
### `--insecure-http-parser`
<!-- YAML
added:
- v13.4.0
- v12.15.0
- v10.19.0
-->
Use an insecure HTTP parser that accepts invalid HTTP headers. This may allow
interoperability with non-conformant HTTP implementations. It may also allow
request smuggling and other HTTP attacks that rely on invalid headers being
accepted. Avoid using this option.
### `--jitless`
<!-- YAML
added: v12.0.0
-->
Disable [runtime allocation of executable memory][jitless]. This may be
required on some platforms for security reasons. It can also reduce attack
surface on other platforms, but the performance impact may be severe.
This flag is inherited from V8 and is subject to change upstream. It may
disappear in a non-semver-major release.
### `--env-file=config`
> Stability: 1.1 - Active development
<!-- YAML
added: REPLACEME
-->
Loads environment variables from a file relative to the current directory,
making them available to applications on `process.env`. The [environment
variables which configure Node.js][environment_variables], such as `NODE_OPTIONS`,
are parsed and applied. If the same variable is defined in the environment and
in the file, the value from the environment takes precedence.