Lines Matching +full:- +full:- +full:exit +full:- +full:code
3 <!-- introduced_in=v0.10.0 -->
5 <!-- type=global -->
7 <!-- source_link=lib/process.js -->
26 <!-- YAML
28 -->
31 no additional work to schedule. Normally, the Node.js process will exit when
40 termination, such as calling [`process.exit()`][] or uncaught exceptions.
42 The `'beforeExit'` should _not_ be used as an alternative to the `'exit'` event
48 process.on('beforeExit', (code) => {
49 console.log('Process beforeExit event with code: ', code);
52 process.on('exit', (code) => {
53 console.log('Process exit event with code: ', code);
60 // Process beforeExit event with code: 0
61 // Process exit event with code: 0
67 process.on('beforeExit', (code) => {
68 console.log('Process beforeExit event with code: ', code);
71 process.on('exit', (code) => {
72 console.log('Process exit event with code: ', code);
79 // Process beforeExit event with code: 0
80 // Process exit event with code: 0
85 <!-- YAML
87 -->
93 ### Event: `'exit'`
95 <!-- YAML
97 -->
99 * `code` {integer}
101 The `'exit'` event is emitted when the Node.js process is about to exit as a
104 * The `process.exit()` method being called explicitly;
108 all `'exit'` listeners have finished running the Node.js process will terminate.
110 The listener callback function is invoked with the exit code specified either
112 [`process.exit()`][] method.
117 process.on('exit', (code) => {
118 console.log(`About to exit with code: ${code}`);
125 process.on('exit', (code) => {
126 console.log(`About to exit with code: ${code}`);
131 process will exit immediately after calling the `'exit'` event listeners
138 process.on('exit', (code) => {
148 process.on('exit', (code) => {
157 <!-- YAML
159 -->
181 <!-- YAML
184 -->
186 > Stability: 0 - Deprecated
213 setImmediate(() => process.exit(1));
242 setImmediate(() => process.exit(1));
268 <!-- YAML
270 -->
287 Another way of stating this is that, unlike in synchronous code where there is
288 an ever-growing list of unhandled exceptions, with Promises there can be a
289 growing-and-shrinking list of unhandled rejections.
291 In synchronous code, the `'uncaughtException'` event is emitted when the list of
294 In asynchronous code, the `'unhandledRejection'` event is emitted when the list
325 likely best for long-running application) or upon process exit (which is likely
330 <!-- YAML
333 - version:
334 - v12.0.0
335 - v10.17.0
336 pr-url: https://github.com/nodejs/node/pull/26599
338 -->
345 [`--unhandled-rejections`][] flag set to `strict` or `throw` (which is the
352 with code 1, overriding any previously set [`process.exitCode`][].
356 provided exit code. Otherwise, in the presence of such handler the process will
357 exit with 0.
400 default behavior to exit the process by installing a
409 code without properly recovering from the exception can cause additional
413 process will exit with a non-zero exit code and the stack trace will be printed.
432 <!-- YAML
434 - v13.7.0
435 - v12.17.0
436 -->
443 [`--unhandled-rejections`][] flag set to `strict` or `throw` (which is the
481 <!-- YAML
484 - version: v7.0.0
485 pr-url: https://github.com/nodejs/node/pull/8217
487 - version: v6.6.0
488 pr-url: https://github.com/nodejs/node/pull/8223
491 -->
560 address such failures, a non-operational
567 <!-- YAML
569 -->
573 * `message` {string} A system-provided description of the warning.
574 * `stack` {string} A stack trace to the location in the code where the warning
583 lead to sub-optimal application performance, bugs, or security vulnerabilities.
605 By default, Node.js will print process warnings to `stderr`. The `--no-warnings`
606 command-line option can be used to suppress the default console output but the
625 $ node --no-warnings
633 The `--trace-warnings` command-line option can be used to have the default
636 Launching Node.js using the `--throw-deprecation` command-line flag will
639 Using the `--trace-deprecation` command-line flag will cause the custom
642 Using the `--no-deprecation` command-line flag will suppress all reporting
645 The `*-deprecation` command-line flags only affect warnings that use the name
650 <!-- YAML
652 - v16.2.0
653 - v14.18.0
654 -->
663 custom or application-specific warnings.
671 * `'DeprecationWarning'` - Indicates use of a deprecated Node.js API or feature.
672 Such warnings must include a `'code'` property identifying the
673 [deprecation code][].
674 * `'ExperimentalWarning'` - Indicates use of an experimental Node.js API or
676 time and are not subject to the same strict semantic-versioning and long-term
678 * `'MaxListenersExceededWarning'` - Indicates that too many listeners for a
681 * `'TimeoutOverflowWarning'` - Indicates that a numeric value that cannot fit
682 within a 32-bit signed integer has been provided to either the `setTimeout()`
684 * `'UnsupportedWarning'` - Indicates use of an unsupported option or feature
690 <!--type=event-->
692 <!--name=SIGINT, SIGHUP, etc.-->
709 // Begin reading from stdin so the process does not exit.
713 console.log('Received SIGINT. Press Control-D to exit.');
728 // Begin reading from stdin so the process does not exit.
732 console.log('Received SIGINT. Press Control-D to exit.');
746 * `'SIGTERM'` and `'SIGINT'` have default handlers on non-Windows platforms that
747 reset the terminal mode before exiting with code `128 + signal number`. If one
749 removed (Node.js will no longer exit).
754 Windows about 10 seconds later. On non-Windows platforms, the default
763 pressed. On non-Windows platforms, it can be listened on, but there is no way
790 <!-- YAML
792 -->
794 The `process.abort()` method causes the Node.js process to exit immediately and
801 <!-- YAML
803 -->
808 read-only `Set` of flags allowable within the [`NODE_OPTIONS`][]
816 * Flags may omit leading single (`-`) or double (`--`) dashes; e.g.,
817 `inspect-brk` for `--inspect-brk`, or `r` for `-r`.
818 * Flags passed through to V8 (as listed in `--v8-options`) may replace
819 one or more _non-leading_ dashes for an underscore, or vice-versa;
820 e.g., `--perf_basic_prof`, `--perf-basic-prof`, `--perf_basic-prof`,
824 e.g., `--stack-trace-limit=100`.
829 passed through to V8 will contain underscores instead of non-leading
836 // -r
837 // --inspect-brk
838 // --abort_on_uncaught_exception
847 // -r
848 // --inspect-brk
849 // --abort_on_uncaught_exception
864 <!-- YAML
866 -->
888 <!-- YAML
890 -->
894 The `process.argv` property returns an array containing the command-line
898 file being executed. The remaining elements will be any additional command-line
901 For example, assuming the following script for `process-args.js`:
924 $ node process-args.js one two=three four
931 1: /Users/mjr/work/node/process-args.js
939 <!-- YAML
941 -->
945 The `process.argv0` property stores a read-only copy of the original value of
949 $ bash -c 'exec -a customArgv0 ./node'
951 '/Volumes/code/external/node/out/Release/node'
958 <!-- YAML
961 - version: v14.0.0
962 pr-url: https://github.com/nodejs/node/pull/30165
964 -->
975 <!-- YAML
977 -->
988 <!-- YAML
990 -->
1001 <!-- YAML
1003 -->
1039 <!-- YAML
1042 - version: v16.0.0
1043 pr-url: https://github.com/nodejs/node/pull/36902
1045 -->
1056 <!-- eslint-skip -->
1086 The `process.config` property is **not** read-only and there are existing
1090 Modifying the `process.config` property, or any child-property of the
1092 read-only in a future release.
1096 <!-- YAML
1098 -->
1112 <!-- YAML
1114 -->
1116 > Stability: 1 - Experimental
1129 <!-- YAML
1131 -->
1142 spent in user and system code respectively, and may end up being greater than
1156 while (Date.now() - now < 500);
1170 while (Date.now() - now < 500);
1178 <!-- YAML
1180 -->
1201 <!-- YAML
1203 -->
1223 <!-- YAML
1225 -->
1229 IPC channel to the parent process, allowing the child process to exit gracefully
1240 <!-- YAML
1243 - version: v9.0.0
1244 pr-url: https://github.com/nodejs/node/pull/12794
1246 -->
1293 <!-- YAML
1295 -->
1301 * `code` {string} A unique identifier for the warning instance being emitted.
1314 // Emit a warning with a code and additional detail.
1316 code: 'MY_WARNING',
1327 // Emit a warning with a code and additional detail.
1329 code: 'MY_WARNING',
1347 console.warn(warning.code); // 'MY_WARNING'
1359 console.warn(warning.code); // 'MY_WARNING'
1367 ## `process.emitWarning(warning[, type[, code]][, ctor])`
1369 <!-- YAML
1371 -->
1376 * `code` {string} A unique identifier for the warning instance being emitted.
1441 console.warn(warning.code);
1452 console.warn(warning.code);
1459 `code` and `ctor` arguments will be ignored):
1468 myWarning.code = 'WARN001';
1481 myWarning.code = 'WARN001';
1496 * If the `--throw-deprecation` command-line flag is used, the deprecation
1498 * If the `--no-deprecation` command-line flag is used, the deprecation
1500 * If the `--trace-deprecation` command-line flag is used, the deprecation
1540 <!-- YAML
1543 - version: v11.14.0
1544 pr-url: https://github.com/nodejs/node/pull/26544
1548 - version: v10.0.0
1549 pr-url: https://github.com/nodejs/node/pull/18990
1551 -->
1560 <!-- eslint-skip -->
1564 TERM: 'xterm-256color',
1583 $ node -e 'process.env.foo = "bar"' && echo $foo
1648 On Windows operating systems, environment variables are case-insensitive.
1671 are visible to the operating system or to native add-ons.
1675 <!-- YAML
1677 -->
1681 The `process.execArgv` property returns the set of Node.js-specific command-line
1689 $ node --harmony script.js --version
1694 <!-- eslint-disable semi -->
1697 ['--harmony']
1702 <!-- eslint-disable semi -->
1705 ['/usr/local/bin/node', 'script.js', '--version']
1713 <!-- YAML
1715 -->
1722 <!-- eslint-disable semi -->
1728 ## `process.exit([code])`
1730 <!-- YAML
1732 -->
1734 * `code` {integer} The exit code. **Default:** `0`.
1736 The `process.exit()` method instructs Node.js to terminate the process
1737 synchronously with an exit status of `code`. If `code` is omitted, exit uses
1738 either the 'success' code `0` or the value of `process.exitCode` if it has been
1739 set. Node.js will not terminate until all the [`'exit'`][] event listeners are
1742 To exit with a 'failure' code:
1745 import { exit } from 'node:process';
1747 exit(1);
1751 const { exit } = require('node:process');
1753 exit(1);
1756 The shell that executed Node.js should see the exit code as `1`.
1758 Calling `process.exit()` will force the process to exit as quickly as possible
1763 In most situations, it is not actually necessary to call `process.exit()`
1764 explicitly. The Node.js process will exit on its own _if there is no additional
1766 tell the process which exit code to use when the process exits gracefully.
1769 `process.exit()` method that could lead to data printed to stdout being
1773 import { exit } from 'node:process';
1778 exit(1);
1783 const { exit } = require('node:process');
1788 exit(1);
1794 event loop. Calling `process.exit()`, however, forces the process to exit
1797 Rather than calling `process.exit()` directly, the code _should_ set the
1798 `process.exitCode` and allow the process to exit naturally by avoiding
1804 // How to properly set the exit code while letting
1805 // the process exit gracefully.
1815 // How to properly set the exit code while letting
1816 // the process exit gracefully.
1825 is safer than calling `process.exit()`.
1832 <!-- YAML
1834 -->
1838 A number which will be the process exit code, when the process either
1839 exits gracefully, or is exited via [`process.exit()`][] without specifying
1840 a code.
1842 Specifying a code to [`process.exit(code)`][`process.exit()`] will override any
1847 <!-- YAML
1849 - v17.3.0
1850 - v16.14.0
1851 -->
1853 > Stability: 1 - Experimental
1887 <!-- YAML
1889 -->
1915 <!-- YAML
1917 -->
1945 <!-- YAML
1947 -->
1975 <!-- YAML
1977 -->
2006 <!-- YAML
2008 -->
2036 <!-- YAML
2038 -->
2047 <!-- YAML
2049 -->
2051 > Stability: 3 - Legacy. Use [`process.hrtime.bigint()`][] instead.
2059 The `process.hrtime()` method returns the current high-resolution real time
2066 user-defined array instead of the result of a previous call to
2107 <!-- YAML
2109 -->
2114 current high-resolution real time in nanoseconds as a `bigint`.
2130 console.log(`Benchmark took ${end - start} nanoseconds`);
2145 console.log(`Benchmark took ${end - start} nanoseconds`);
2152 <!-- YAML
2154 -->
2192 <!-- YAML
2194 -->
2224 process.exit(0);
2239 process.exit(0);
2250 <!-- YAML
2253 -->
2255 > Stability: 0 - Deprecated: Use [`require.main`][] instead.
2270 <!-- YAML
2273 - version:
2274 - v13.9.0
2275 - v12.17.0
2276 pr-url: https://github.com/nodejs/node/pull/31550
2278 - version: v7.2.0
2279 pr-url: https://github.com/nodejs/node/pull/9587
2281 -->
2326 process, including all C++ and JavaScript objects and code.
2342 <!-- YAML
2344 - v15.6.0
2345 - v14.18.0
2346 -->
2355 process, including all C++ and JavaScript objects and code.
2376 <!-- YAML
2379 - version: v18.0.0
2380 pr-url: https://github.com/nodejs/node/pull/41678
2384 - version: v1.8.1
2385 pr-url: https://github.com/nodejs/node/pull/1077
2387 -->
2556 In simple scenarios, `queueMicrotask()` can be a drop-in replacement for
2571 One note-worthy difference between the two APIs is that `process.nextTick()`
2601 <!-- YAML
2603 -->
2607 The `process.noDeprecation` property indicates whether the `--no-deprecation`
2615 <!-- YAML
2617 -->
2637 <!-- YAML
2639 -->
2674 <!-- YAML
2676 - v9.2.0
2677 - v8.10.0
2678 - v6.13.0
2679 -->
2700 <!-- YAML
2703 - version: v4.2.0
2704 pr-url: https://github.com/nodejs/node/pull/3212
2706 -->
2711 to the current release, including URLs for the source tarball and headers-only
2718 the source code of the current release.
2722 Node.js native add-ons.
2725 used for compiling Node.js native add-ons. _This property is only present on
2730 LTS Release code names (including those that are no longer supported).
2734 …For other LTS Release code names, see [Node.js Changelog Archive](https://github.com/nodejs/node/b…
2736 <!-- eslint-skip -->
2742 sourceUrl: 'https://nodejs.org/download/release/v18.12.0/node-v18.12.0.tar.gz',
2743 headersUrl: 'https://nodejs.org/download/release/v18.12.0/node-v18.12.0-headers.tar.gz',
2744 libUrl: 'https://nodejs.org/download/release/v18.12.0/win-x64/node.lib'
2748 In custom builds from non-release versions of the source tree, only the
2754 <!-- YAML
2757 - version:
2758 - v13.12.0
2759 - v12.17.0
2760 pr-url: https://github.com/nodejs/node/pull/32242
2762 -->
2772 <!-- YAML
2774 - v13.12.0
2775 - v12.17.0
2776 -->
2780 Write reports in a compact format, single-line JSON, more easily consumable
2781 by log processing systems than the default multi-line format designed for
2798 <!-- YAML
2801 - version:
2802 - v13.12.0
2803 - v12.17.0
2804 pr-url: https://github.com/nodejs/node/pull/32242
2806 -->
2828 <!-- YAML
2831 - version:
2832 - v13.12.0
2833 - v12.17.0
2834 pr-url: https://github.com/nodejs/node/pull/32242
2836 -->
2861 <!-- YAML
2864 - version:
2865 - v13.12.0
2866 - v12.17.0
2867 pr-url: https://github.com/nodejs/node/pull/32242
2869 -->
2887 fs.writeFileSync('my-report.log', util.inspect(data), 'utf8');
2899 fs.writeFileSync('my-report.log', util.inspect(data), 'utf8');
2906 <!-- YAML
2909 - version:
2910 - v15.0.0
2911 - v14.17.0
2912 pr-url: https://github.com/nodejs/node/pull/35654
2914 -->
2935 <!-- YAML
2938 - version:
2939 - v13.12.0
2940 - v12.17.0
2941 pr-url: https://github.com/nodejs/node/pull/32242
2943 -->
2964 <!-- YAML
2967 - version:
2968 - v13.12.0
2969 - v12.17.0
2970 pr-url: https://github.com/nodejs/node/pull/32242
2972 -->
2992 <!-- YAML
2995 - version:
2996 - v13.12.0
2997 - v12.17.0
2998 pr-url: https://github.com/nodejs/node/pull/32242
3000 -->
3021 <!-- YAML
3024 - version:
3025 - v13.12.0
3026 - v12.17.0
3027 pr-url: https://github.com/nodejs/node/pull/32242
3029 -->
3063 <!-- YAML
3065 -->
3166 <!-- YAML
3168 -->
3192 <!-- YAML
3194 -->
3237 <!-- YAML
3239 -->
3282 <!-- YAML
3284 -->
3327 <!-- YAML
3329 -->
3371 <!-- YAML
3373 -->
3416 <!-- YAML
3418 - v16.6.0
3419 - v14.18.0
3420 -->
3422 > Stability: 1 - Experimental
3430 `--enable-source-maps`.
3437 <!-- YAML
3439 -->
3448 not be emitted. If `--abort-on-uncaught-exception` was passed from the
3455 method with a non-`null` argument while another capture function is set will
3459 [`domain`][] built-in module.
3560 `process.exit()` is called before an asynchronous write completes. See
3561 [`process.exit()`][] for more information.
3578 $ node -p "Boolean(process.stdin.isTTY)"
3580 $ echo "foo" | node -p "Boolean(process.stdin.isTTY)"
3582 $ node -p "Boolean(process.stdout.isTTY)"
3584 $ node -p "Boolean(process.stdout.isTTY)" | cat
3592 <!-- YAML
3594 -->
3599 `--throw-deprecation` flag is set on the current Node.js process.
3606 $ node --throw-deprecation -p "process.throwDeprecation"
3608 $ node -p "process.throwDeprecation"
3623 <!-- YAML
3625 -->
3636 binary name plus the length of the command-line arguments because setting the
3648 <!-- YAML
3650 -->
3655 `--trace-deprecation` flag is set on the current Node.js process. See the
3662 <!-- YAML
3665 - version:
3666 - v14.0.0
3667 - v12.19.0
3668 pr-url: https://github.com/nodejs/node/pull/32499
3670 -->
3672 > Stability: 0 - Deprecated. Calling `process.umask()` with no argument causes
3673 > the process-wide umask to be written twice. This introduces a race condition
3675 > cross-platform alternative API.
3682 <!-- YAML
3684 -->
3715 <!-- YAML
3717 -->
3729 <!-- YAML
3731 -->
3756 <!-- YAML
3759 - version: v9.0.0
3760 pr-url: https://github.com/nodejs/node/pull/15785
3762 - version: v4.2.0
3763 pr-url: https://github.com/nodejs/node/pull/3102
3765 -->
3790 v8: '7.0.276.38-node.18',
3806 ## Exit codes
3808 Node.js will normally exit with a `0` status code when no more async
3816 * `3` **Internal JavaScript Parse Error**: The JavaScript source code
3821 source code internal in the Node.js bootstrapping process failed to
3827 * `6` **Non-function Internal Exception Handler**: There was an
3829 function was somehow set to a non-function, and could not be called.
3830 * `7` **Internal Exception Handler Run-Time Failure**: There was an
3835 * `8`: Unused. In previous versions of Node.js, exit code 8 sometimes
3839 * `10` **Internal JavaScript Run-Time Failure**: The JavaScript
3840 source code internal in the Node.js bootstrapping process threw an error
3843 * `12` **Invalid Debug Argument**: The `--inspect` and/or `--inspect-brk`
3845 * `13` **Unfinished Top-Level Await**: `await` was used outside of a function
3846 in the top-level code, but the passed `Promise` never resolved.
3851 `SIGKILL` or `SIGHUP`, then its exit code will be `128` plus the
3852 value of the signal code. This is a standard POSIX practice, since
3853 exit codes are defined to be 7-bit integers, and signal exits set
3854 the high-order bit, and then contain the value of the signal code.
3855 For example, signal `SIGABRT` has value `6`, so the expected exit
3856 code will be `128` + `6`, or `134`.
3858 [Advanced serialization for `child_process`]: child_process.md#advanced-serialization
3859 …g]: https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os
3862 [Duplex]: stream.md#duplex-and-transform-streams
3863 [Event Loop]: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick
3865 [Readable]: stream.md#readable-streams
3866 [Signal Events]: #signal-events
3868 [Stream compatibility]: stream.md#compatibility-with-older-nodejs-versions
3870 [Writable]: stream.md#writable-streams
3871 [`'exit'`]: #event-exit
3872 [`'message'`]: child_process.md#event-message
3873 [`'uncaughtException'`]: #event-uncaughtexception
3874 [`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode
3877 [`ChildProcess.send()`]: child_process.md#subprocesssendmessage-sendhandle-options-callback
3878 [`ChildProcess`]: child_process.md#class-childprocess
3879 [`Error`]: errors.md#class-error
3880 [`EventEmitter`]: events.md#class-eventemitter
3882 [`Promise.race()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Object…
3883 [`Worker`]: worker_threads.md#class-worker
3884 [`Worker` constructor]: worker_threads.md#new-workerfilename-options
3885 [`console.error()`]: console.md#consoleerrordata-args
3886 [`console.log()`]: console.md#consolelogdata-args
3888 [`net.Server`]: net.md#class-netserver
3889 [`net.Socket`]: net.md#class-netsocket
3890 [`os.constants.dlopen`]: os.md#dlopen-constants
3894 [`process.exit()`]: #processexitcode
3898 [`process.kill()`]: #processkillpid-signal
3900 [`promise.catch()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objec…
3904 [`require.main`]: modules.md#accessing-the-main-module
3908 [deprecation code]: deprecations.md
3909 [note on process I/O]: #a-note-on-process-io
3911 [process_emit_warning]: #processemitwarningwarning-type-code-ctor
3912 [process_warning]: #event-warning