• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html lang="en">
3<head>
4  <meta charset="utf-8">
5  <meta name="viewport" content="width=device-width">
6  <meta name="nodejs.org:node-version" content="v14.19.1">
7  <title>Process | Node.js v14.19.1 Documentation</title>
8  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
9  <link rel="stylesheet" href="assets/style.css">
10  <link rel="stylesheet" href="assets/hljs.css">
11  <link rel="canonical" href="https://nodejs.org/api/process.html">
12</head>
13<body class="alt apidoc" id="api-section-process">
14  <div id="content" class="clearfix">
15    <div id="column2" class="interior">
16      <div id="intro" class="interior">
17        <a href="/" title="Go back to the home page">
18          Node.js
19        </a>
20      </div>
21      <ul>
22<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
23<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
24</ul>
25<hr class="line">
26<ul>
27<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
28<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
29<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
30<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
31<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
32<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
33<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
34<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
35<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
36<li><a href="console.html" class="nav-console">Console</a></li>
37<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
38<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
39<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
40<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
41<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
42<li><a href="dns.html" class="nav-dns">DNS</a></li>
43<li><a href="domain.html" class="nav-domain">Domain</a></li>
44<li><a href="errors.html" class="nav-errors">Errors</a></li>
45<li><a href="events.html" class="nav-events">Events</a></li>
46<li><a href="fs.html" class="nav-fs">File system</a></li>
47<li><a href="globals.html" class="nav-globals">Globals</a></li>
48<li><a href="http.html" class="nav-http">HTTP</a></li>
49<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
50<li><a href="https.html" class="nav-https">HTTPS</a></li>
51<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
52<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
53<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
54<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
55<li><a href="module.html" class="nav-module">Modules: <code>module</code> API</a></li>
56<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
57<li><a href="net.html" class="nav-net">Net</a></li>
58<li><a href="os.html" class="nav-os">OS</a></li>
59<li><a href="path.html" class="nav-path">Path</a></li>
60<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
61<li><a href="policy.html" class="nav-policy">Policies</a></li>
62<li><a href="process.html" class="nav-process active">Process</a></li>
63<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
64<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
65<li><a href="readline.html" class="nav-readline">Readline</a></li>
66<li><a href="repl.html" class="nav-repl">REPL</a></li>
67<li><a href="report.html" class="nav-report">Report</a></li>
68<li><a href="stream.html" class="nav-stream">Stream</a></li>
69<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
70<li><a href="timers.html" class="nav-timers">Timers</a></li>
71<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
72<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
73<li><a href="tty.html" class="nav-tty">TTY</a></li>
74<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
75<li><a href="url.html" class="nav-url">URL</a></li>
76<li><a href="util.html" class="nav-util">Utilities</a></li>
77<li><a href="v8.html" class="nav-v8">V8</a></li>
78<li><a href="vm.html" class="nav-vm">VM</a></li>
79<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
80<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
81<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
82</ul>
83<hr class="line">
84<ul>
85<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
86</ul>
87    </div>
88
89    <div id="column1" data-id="process" class="interior">
90      <header>
91        <div class="header-container">
92          <h1>Node.js v14.19.1 documentation</h1>
93          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
94            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
95              <path fill="none" d="M0 0h24v24H0z" />
96              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
97              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
98            </svg>
99            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
100              <path d="M0 0h24v24H0z" fill="none" />
101              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
102            </svg>
103          </button>
104        </div>
105        <div id="gtoc">
106          <ul>
107            <li>
108              <a href="index.html">Index</a>
109            </li>
110            <li>
111              <a href="all.html">View on single page</a>
112            </li>
113            <li>
114              <a href="process.json">View as JSON</a>
115            </li>
116
117    <li class="version-picker">
118      <a href="#">View another version <span>&#x25bc;</span></a>
119      <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v17.x/api/process.html">17.x</a></li>
120<li><a href="https://nodejs.org/docs/latest-v16.x/api/process.html">16.x <b>LTS</b></a></li>
121<li><a href="https://nodejs.org/docs/latest-v15.x/api/process.html">15.x</a></li>
122<li><a href="https://nodejs.org/docs/latest-v14.x/api/process.html">14.x <b>LTS</b></a></li>
123<li><a href="https://nodejs.org/docs/latest-v13.x/api/process.html">13.x</a></li>
124<li><a href="https://nodejs.org/docs/latest-v12.x/api/process.html">12.x <b>LTS</b></a></li>
125<li><a href="https://nodejs.org/docs/latest-v11.x/api/process.html">11.x</a></li>
126<li><a href="https://nodejs.org/docs/latest-v10.x/api/process.html">10.x</a></li>
127<li><a href="https://nodejs.org/docs/latest-v9.x/api/process.html">9.x</a></li>
128<li><a href="https://nodejs.org/docs/latest-v8.x/api/process.html">8.x</a></li>
129<li><a href="https://nodejs.org/docs/latest-v7.x/api/process.html">7.x</a></li>
130<li><a href="https://nodejs.org/docs/latest-v6.x/api/process.html">6.x</a></li>
131<li><a href="https://nodejs.org/docs/latest-v5.x/api/process.html">5.x</a></li>
132<li><a href="https://nodejs.org/docs/latest-v4.x/api/process.html">4.x</a></li>
133<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/process.html">0.12.x</a></li>
134<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/process.html">0.10.x</a></li></ol>
135    </li>
136
137            <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/process.md">Edit on GitHub</a></li>
138          </ul>
139        </div>
140        <hr>
141      </header>
142
143      <details id="toc" open><summary>Table of contents</summary><ul>
144<li><a href="#process_process">Process</a>
145<ul>
146<li><a href="#process_process_events">Process events</a>
147<ul>
148<li><a href="#process_event_beforeexit">Event: <code>'beforeExit'</code></a></li>
149<li><a href="#process_event_disconnect">Event: <code>'disconnect'</code></a></li>
150<li><a href="#process_event_exit">Event: <code>'exit'</code></a></li>
151<li><a href="#process_event_message">Event: <code>'message'</code></a></li>
152<li><a href="#process_event_multipleresolves">Event: <code>'multipleResolves'</code></a></li>
153<li><a href="#process_event_rejectionhandled">Event: <code>'rejectionHandled'</code></a></li>
154<li><a href="#process_event_uncaughtexception">Event: <code>'uncaughtException'</code></a>
155<ul>
156<li><a href="#process_warning_using_uncaughtexception_correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li>
157</ul>
158</li>
159<li><a href="#process_event_uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li>
160<li><a href="#process_event_unhandledrejection">Event: <code>'unhandledRejection'</code></a></li>
161<li><a href="#process_event_warning">Event: <code>'warning'</code></a></li>
162<li><a href="#process_event_worker">Event: <code>'worker'</code></a>
163<ul>
164<li><a href="#process_emitting_custom_warnings">Emitting custom warnings</a></li>
165<li><a href="#process_node_js_warning_names">Node.js warning names</a></li>
166</ul>
167</li>
168<li><a href="#process_signal_events">Signal events</a></li>
169</ul>
170</li>
171<li><a href="#process_process_abort"><code>process.abort()</code></a></li>
172<li><a href="#process_process_allowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li>
173<li><a href="#process_process_arch"><code>process.arch</code></a></li>
174<li><a href="#process_process_argv"><code>process.argv</code></a></li>
175<li><a href="#process_process_argv0"><code>process.argv0</code></a></li>
176<li><a href="#process_process_channel"><code>process.channel</code></a>
177<ul>
178<li><a href="#process_process_channel_ref"><code>process.channel.ref()</code></a></li>
179<li><a href="#process_process_channel_unref"><code>process.channel.unref()</code></a></li>
180</ul>
181</li>
182<li><a href="#process_process_chdir_directory"><code>process.chdir(directory)</code></a></li>
183<li><a href="#process_process_config"><code>process.config</code></a></li>
184<li><a href="#process_process_connected"><code>process.connected</code></a></li>
185<li><a href="#process_process_cpuusage_previousvalue"><code>process.cpuUsage([previousValue])</code></a></li>
186<li><a href="#process_process_cwd"><code>process.cwd()</code></a></li>
187<li><a href="#process_process_debugport"><code>process.debugPort</code></a></li>
188<li><a href="#process_process_disconnect"><code>process.disconnect()</code></a></li>
189<li><a href="#process_process_dlopen_module_filename_flags"><code>process.dlopen(module, filename[, flags])</code></a></li>
190<li><a href="#process_process_emitwarning_warning_options"><code>process.emitWarning(warning[, options])</code></a></li>
191<li><a href="#process_process_emitwarning_warning_type_code_ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a>
192<ul>
193<li><a href="#process_avoiding_duplicate_warnings">Avoiding duplicate warnings</a></li>
194</ul>
195</li>
196<li><a href="#process_process_env"><code>process.env</code></a></li>
197<li><a href="#process_process_execargv"><code>process.execArgv</code></a></li>
198<li><a href="#process_process_execpath"><code>process.execPath</code></a></li>
199<li><a href="#process_process_exit_code"><code>process.exit([code])</code></a></li>
200<li><a href="#process_process_exitcode"><code>process.exitCode</code></a></li>
201<li><a href="#process_process_getegid"><code>process.getegid()</code></a></li>
202<li><a href="#process_process_geteuid"><code>process.geteuid()</code></a></li>
203<li><a href="#process_process_getgid"><code>process.getgid()</code></a></li>
204<li><a href="#process_process_getgroups"><code>process.getgroups()</code></a></li>
205<li><a href="#process_process_getuid"><code>process.getuid()</code></a></li>
206<li><a href="#process_process_hasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li>
207<li><span class="stability_3"><a href="#process_process_hrtime_time"><code>process.hrtime([time])</code></a></span></li>
208<li><a href="#process_process_hrtime_bigint"><code>process.hrtime.bigint()</code></a></li>
209<li><a href="#process_process_initgroups_user_extragroup"><code>process.initgroups(user, extraGroup)</code></a></li>
210<li><a href="#process_process_kill_pid_signal"><code>process.kill(pid[, signal])</code></a></li>
211<li><span class="stability_0"><a href="#process_process_mainmodule"><code>process.mainModule</code></a></span></li>
212<li><a href="#process_process_memoryusage"><code>process.memoryUsage()</code></a></li>
213<li><a href="#process_process_memoryusage_rss"><code>process.memoryUsage.rss()</code></a></li>
214<li><a href="#process_process_nexttick_callback_args"><code>process.nextTick(callback[, ...args])</code></a>
215<ul>
216<li><a href="#process_when_to_use_queuemicrotask_vs_process_nexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li>
217</ul>
218</li>
219<li><a href="#process_process_nodeprecation"><code>process.noDeprecation</code></a></li>
220<li><a href="#process_process_pid"><code>process.pid</code></a></li>
221<li><a href="#process_process_platform"><code>process.platform</code></a></li>
222<li><a href="#process_process_ppid"><code>process.ppid</code></a></li>
223<li><a href="#process_process_release"><code>process.release</code></a></li>
224<li><a href="#process_process_report"><code>process.report</code></a>
225<ul>
226<li><a href="#process_process_report_compact"><code>process.report.compact</code></a></li>
227<li><a href="#process_process_report_directory"><code>process.report.directory</code></a></li>
228<li><a href="#process_process_report_filename"><code>process.report.filename</code></a></li>
229<li><a href="#process_process_report_getreport_err"><code>process.report.getReport([err])</code></a></li>
230<li><a href="#process_process_report_reportonfatalerror"><code>process.report.reportOnFatalError</code></a></li>
231<li><a href="#process_process_report_reportonsignal"><code>process.report.reportOnSignal</code></a></li>
232<li><a href="#process_process_report_reportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li>
233<li><a href="#process_process_report_signal"><code>process.report.signal</code></a></li>
234<li><a href="#process_process_report_writereport_filename_err"><code>process.report.writeReport([filename][, err])</code></a></li>
235</ul>
236</li>
237<li><a href="#process_process_resourceusage"><code>process.resourceUsage()</code></a></li>
238<li><a href="#process_process_send_message_sendhandle_options_callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li>
239<li><a href="#process_process_setegid_id"><code>process.setegid(id)</code></a></li>
240<li><a href="#process_process_seteuid_id"><code>process.seteuid(id)</code></a></li>
241<li><a href="#process_process_setgid_id"><code>process.setgid(id)</code></a></li>
242<li><a href="#process_process_setgroups_groups"><code>process.setgroups(groups)</code></a></li>
243<li><a href="#process_process_setuid_id"><code>process.setuid(id)</code></a></li>
244<li><span class="stability_1"><a href="#process_process_setsourcemapsenabled_val"><code>process.setSourceMapsEnabled(val)</code></a></span></li>
245<li><a href="#process_process_setuncaughtexceptioncapturecallback_fn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li>
246<li><a href="#process_process_stderr"><code>process.stderr</code></a>
247<ul>
248<li><a href="#process_process_stderr_fd"><code>process.stderr.fd</code></a></li>
249</ul>
250</li>
251<li><a href="#process_process_stdin"><code>process.stdin</code></a>
252<ul>
253<li><a href="#process_process_stdin_fd"><code>process.stdin.fd</code></a></li>
254</ul>
255</li>
256<li><a href="#process_process_stdout"><code>process.stdout</code></a>
257<ul>
258<li><a href="#process_process_stdout_fd"><code>process.stdout.fd</code></a></li>
259<li><a href="#process_a_note_on_process_i_o">A note on process I/O</a></li>
260</ul>
261</li>
262<li><a href="#process_process_throwdeprecation"><code>process.throwDeprecation</code></a></li>
263<li><a href="#process_process_title"><code>process.title</code></a></li>
264<li><a href="#process_process_tracedeprecation"><code>process.traceDeprecation</code></a></li>
265<li><span class="stability_0"><a href="#process_process_umask"><code>process.umask()</code></a></span></li>
266<li><a href="#process_process_umask_mask"><code>process.umask(mask)</code></a></li>
267<li><a href="#process_process_uptime"><code>process.uptime()</code></a></li>
268<li><a href="#process_process_version"><code>process.version</code></a></li>
269<li><a href="#process_process_versions"><code>process.versions</code></a></li>
270<li><a href="#process_exit_codes">Exit codes</a></li>
271</ul>
272</li>
273</ul></details>
274
275      <div id="apicontent">
276        <h2>Process<span><a class="mark" href="#process_process" id="process_process">#</a></span></h2>
277
278
279<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v14.19.1/lib/process.js">lib/process.js</a></p>
280<p>The <code>process</code> object is a <code>global</code> that provides information about, and control
281over, the current Node.js process. As a global, it is always available to
282Node.js applications without using <code>require()</code>. It can also be explicitly
283accessed using <code>require()</code>:</p>
284<pre><code class="language-js"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'process'</span>);</code></pre>
285<section><h3>Process events<span><a class="mark" href="#process_process_events" id="process_process_events">#</a></span></h3>
286<p>The <code>process</code> object is an instance of <a href="events.html#events_class_eventemitter"><code>EventEmitter</code></a>.</p>
287<h4>Event: <code>'beforeExit'</code><span><a class="mark" href="#process_event_beforeexit" id="process_event_beforeexit">#</a></span></h4>
288<div class="api_metadata">
289<span>Added in: v0.11.12</span>
290</div>
291<p>The <code>'beforeExit'</code> event is emitted when Node.js empties its event loop and has
292no additional work to schedule. Normally, the Node.js process will exit when
293there is no work scheduled, but a listener registered on the <code>'beforeExit'</code>
294event can make asynchronous calls, and thereby cause the Node.js process to
295continue.</p>
296<p>The listener callback function is invoked with the value of
297<a href="#process_process_exitcode"><code>process.exitCode</code></a> passed as the only argument.</p>
298<p>The <code>'beforeExit'</code> event is <em>not</em> emitted for conditions causing explicit
299termination, such as calling <a href="#process_process_exit_code"><code>process.exit()</code></a> or uncaught exceptions.</p>
300<p>The <code>'beforeExit'</code> should <em>not</em> be used as an alternative to the <code>'exit'</code> event
301unless the intention is to schedule additional work.</p>
302<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
303  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Process beforeExit event with code: '</span>, code);
304});
305
306process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
307  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Process exit event with code: '</span>, code);
308});
309
310<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>);
311
312<span class="hljs-comment">// Prints:</span>
313<span class="hljs-comment">// This message is displayed first.</span>
314<span class="hljs-comment">// Process beforeExit event with code: 0</span>
315<span class="hljs-comment">// Process exit event with code: 0</span></code></pre>
316<h4>Event: <code>'disconnect'</code><span><a class="mark" href="#process_event_disconnect" id="process_event_disconnect">#</a></span></h4>
317<div class="api_metadata">
318<span>Added in: v0.7.7</span>
319</div>
320<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
321and <a href="cluster.html">Cluster</a> documentation), the <code>'disconnect'</code> event will be emitted when
322the IPC channel is closed.</p>
323<h4>Event: <code>'exit'</code><span><a class="mark" href="#process_event_exit" id="process_event_exit">#</a></span></h4>
324<div class="api_metadata">
325<span>Added in: v0.1.7</span>
326</div>
327<ul>
328<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
329</ul>
330<p>The <code>'exit'</code> event is emitted when the Node.js process is about to exit as a
331result of either:</p>
332<ul>
333<li>The <code>process.exit()</code> method being called explicitly;</li>
334<li>The Node.js event loop no longer having any additional work to perform.</li>
335</ul>
336<p>There is no way to prevent the exiting of the event loop at this point, and once
337all <code>'exit'</code> listeners have finished running the Node.js process will terminate.</p>
338<p>The listener callback function is invoked with the exit code specified either
339by the <a href="#process_process_exitcode"><code>process.exitCode</code></a> property, or the <code>exitCode</code> argument passed to the
340<a href="#process_process_exit_code"><code>process.exit()</code></a> method.</p>
341<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
342  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`About to exit with code: <span class="hljs-subst">${code}</span>`</span>);
343});</code></pre>
344<p>Listener functions <strong>must</strong> only perform <strong>synchronous</strong> operations. The Node.js
345process will exit immediately after calling the <code>'exit'</code> event listeners
346causing any additional work still queued in the event loop to be abandoned.
347In the following example, for instance, the timeout will never occur:</p>
348<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
349  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
350    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>);
351  }, <span class="hljs-number">0</span>);
352});</code></pre>
353<h4>Event: <code>'message'</code><span><a class="mark" href="#process_event_message" id="process_event_message">#</a></span></h4>
354<div class="api_metadata">
355<span>Added in: v0.5.10</span>
356</div>
357<ul>
358<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type">&#x3C;null></a> a parsed JSON object
359or a serializable primitive value.</li>
360<li><code>sendHandle</code> <a href="net.html#net_class_net_server" class="type">&#x3C;net.Server></a> | <a href="net.html#net_class_net_socket" class="type">&#x3C;net.Socket></a> a <a href="net.html#net_class_net_server"><code>net.Server</code></a> or <a href="net.html#net_class_net_socket"><code>net.Socket</code></a>
361object, or undefined.</li>
362</ul>
363<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
364and <a href="cluster.html">Cluster</a> documentation), the <code>'message'</code> event is emitted whenever a
365message sent by a parent process using <a href="child_process.html#child_process_subprocess_send_message_sendhandle_options_callback"><code>childprocess.send()</code></a> is received by
366the child process.</p>
367<p>The message goes through serialization and parsing. The resulting message might
368not be the same as what is originally sent.</p>
369<p>If the <code>serialization</code> option was set to <code>advanced</code> used when spawning the
370process, the <code>message</code> argument can contain data that JSON is not able
371to represent.
372See <a href="child_process.html#child_process_advanced_serialization">Advanced serialization for <code>child_process</code></a> for more details.</p>
373<h4>Event: <code>'multipleResolves'</code><span><a class="mark" href="#process_event_multipleresolves" id="process_event_multipleresolves">#</a></span></h4>
374<div class="api_metadata">
375<span>Added in: v10.12.0</span>
376</div>
377<ul>
378<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The resolution type. One of <code>'resolve'</code> or <code>'reject'</code>.</li>
379<li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> The promise that resolved or rejected more than once.</li>
380<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The value with which the promise was either resolved or
381rejected after the original resolve.</li>
382</ul>
383<p>The <code>'multipleResolves'</code> event is emitted whenever a <code>Promise</code> has been either:</p>
384<ul>
385<li>Resolved more than once.</li>
386<li>Rejected more than once.</li>
387<li>Rejected after resolve.</li>
388<li>Resolved after reject.</li>
389</ul>
390<p>This is useful for tracking potential errors in an application while using the
391<code>Promise</code> constructor, as multiple resolutions are silently swallowed. However,
392the occurrence of this event does not necessarily indicate an error. For
393example, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race"><code>Promise.race()</code></a> can trigger a <code>'multipleResolves'</code> event.</p>
394<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'multipleResolves'</span>, <span class="hljs-function">(<span class="hljs-params">type, promise, reason</span>) =></span> {
395  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason);
396  <span class="hljs-title function_">setImmediate</span>(<span class="hljs-function">() =></span> process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>));
397});
398
399<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
400  <span class="hljs-keyword">try</span> {
401    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =></span> {
402      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>);
403      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</span>);
404      <span class="hljs-title function_">reject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Swallowed reject'</span>));
405    });
406  } <span class="hljs-keyword">catch</span> {
407    <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Failed'</span>);
408  }
409}
410
411<span class="hljs-title function_">main</span>().<span class="hljs-title function_">then</span>(<span class="hljs-variable language_">console</span>.<span class="hljs-property">log</span>);
412<span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span>
413<span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span>
414<span class="hljs-comment">//     at Promise (*)</span>
415<span class="hljs-comment">//     at new Promise (&#x3C;anonymous>)</span>
416<span class="hljs-comment">//     at main (*)</span>
417<span class="hljs-comment">// First call</span></code></pre>
418<h4>Event: <code>'rejectionHandled'</code><span><a class="mark" href="#process_event_rejectionhandled" id="process_event_rejectionhandled">#</a></span></h4>
419<div class="api_metadata">
420<span>Added in: v1.4.1</span>
421</div>
422<ul>
423<li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> The late handled promise.</li>
424</ul>
425<p>The <code>'rejectionHandled'</code> event is emitted whenever a <code>Promise</code> has been rejected
426and an error handler was attached to it (using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch"><code>promise.catch()</code></a>, for
427example) later than one turn of the Node.js event loop.</p>
428<p>The <code>Promise</code> object would have previously been emitted in an
429<code>'unhandledRejection'</code> event, but during the course of processing gained a
430rejection handler.</p>
431<p>There is no notion of a top level for a <code>Promise</code> chain at which rejections can
432always be handled. Being inherently asynchronous in nature, a <code>Promise</code>
433rejection can be handled at a future point in time, possibly much later than
434the event loop turn it takes for the <code>'unhandledRejection'</code> event to be emitted.</p>
435<p>Another way of stating this is that, unlike in synchronous code where there is
436an ever-growing list of unhandled exceptions, with Promises there can be a
437growing-and-shrinking list of unhandled rejections.</p>
438<p>In synchronous code, the <code>'uncaughtException'</code> event is emitted when the list of
439unhandled exceptions grows.</p>
440<p>In asynchronous code, the <code>'unhandledRejection'</code> event is emitted when the list
441of unhandled rejections grows, and the <code>'rejectionHandled'</code> event is emitted
442when the list of unhandled rejections shrinks.</p>
443<pre><code class="language-js"><span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
444process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> {
445  unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason);
446});
447process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> {
448  unhandledRejections.<span class="hljs-title function_">delete</span>(promise);
449});</code></pre>
450<p>In this example, the <code>unhandledRejections</code> <code>Map</code> will grow and shrink over time,
451reflecting rejections that start unhandled and then become handled. It is
452possible to record such errors in an error log, either periodically (which is
453likely best for long-running application) or upon process exit (which is likely
454most convenient for scripts).</p>
455<h4>Event: <code>'uncaughtException'</code><span><a class="mark" href="#process_event_uncaughtexception" id="process_event_uncaughtexception">#</a></span></h4>
456<div class="api_metadata">
457<details class="changelog"><summary>History</summary>
458<table>
459<tbody><tr><th>Version</th><th>Changes</th></tr>
460<tr><td>v12.0.0, v10.17.0</td>
461<td><p>Added the <code>origin</code> argument.</p></td></tr>
462<tr><td>v0.1.18</td>
463<td><p><span>Added in: v0.1.18</span></p></td></tr>
464</tbody></table>
465</details>
466</div>
467<ul>
468<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> The uncaught exception.</li>
469<li><code>origin</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Indicates if the exception originates from an unhandled
470rejection or from an synchronous error. Can either be <code>'uncaughtException'</code> or
471<code>'unhandledRejection'</code>. The latter is only used in conjunction with the
472<a href="cli.html#cli_unhandled_rejections_mode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> and
473an unhandled rejection.</li>
474</ul>
475<p>The <code>'uncaughtException'</code> event is emitted when an uncaught JavaScript
476exception bubbles all the way back to the event loop. By default, Node.js
477handles such exceptions by printing the stack trace to <code>stderr</code> and exiting
478with code 1, overriding any previously set <a href="#process_process_exitcode"><code>process.exitCode</code></a>.
479Adding a handler for the <code>'uncaughtException'</code> event overrides this default
480behavior. Alternatively, change the <a href="#process_process_exitcode"><code>process.exitCode</code></a> in the
481<code>'uncaughtException'</code> handler which will result in the process exiting with the
482provided exit code. Otherwise, in the presence of such handler the process will
483exit with 0.</p>
484<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtException'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> {
485  fs.<span class="hljs-title function_">writeSync</span>(
486    process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>,
487    <span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> +
488    <span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>`</span>
489  );
490});
491
492<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
493  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>);
494}, <span class="hljs-number">500</span>);
495
496<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
497<span class="hljs-title function_">nonexistentFunc</span>();
498<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run.'</span>);</code></pre>
499<p>It is possible to monitor <code>'uncaughtException'</code> events without overriding the
500default behavior to exit the process by installing a
501<code>'uncaughtExceptionMonitor'</code> listener.</p>
502<h5>Warning: Using <code>'uncaughtException'</code> correctly<span><a class="mark" href="#process_warning_using_uncaughtexception_correctly" id="process_warning_using_uncaughtexception_correctly">#</a></span></h5>
503<p><code>'uncaughtException'</code> is a crude mechanism for exception handling
504intended to be used only as a last resort. The event <em>should not</em> be used as
505an equivalent to <code>On Error Resume Next</code>. Unhandled exceptions inherently mean
506that an application is in an undefined state. Attempting to resume application
507code without properly recovering from the exception can cause additional
508unforeseen and unpredictable issues.</p>
509<p>Exceptions thrown from within the event handler will not be caught. Instead the
510process will exit with a non-zero exit code and the stack trace will be printed.
511This is to avoid infinite recursion.</p>
512<p>Attempting to resume normally after an uncaught exception can be similar to
513pulling out the power cord when upgrading a computer. Nine out of ten
514times, nothing happens. But the tenth time, the system becomes corrupted.</p>
515<p>The correct use of <code>'uncaughtException'</code> is to perform synchronous cleanup
516of allocated resources (e.g. file descriptors, handles, etc) before shutting
517down the process. <strong>It is not safe to resume normal operation after
518<code>'uncaughtException'</code>.</strong></p>
519<p>To restart a crashed application in a more reliable way, whether
520<code>'uncaughtException'</code> is emitted or not, an external monitor should be employed
521in a separate process to detect application failures and recover or restart as
522needed.</p>
523<h4>Event: <code>'uncaughtExceptionMonitor'</code><span><a class="mark" href="#process_event_uncaughtexceptionmonitor" id="process_event_uncaughtexceptionmonitor">#</a></span></h4>
524<div class="api_metadata">
525<span>Added in: v13.7.0</span>
526</div>
527<ul>
528<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> The uncaught exception.</li>
529<li><code>origin</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Indicates if the exception originates from an unhandled
530rejection or from synchronous errors. Can either be <code>'uncaughtException'</code> or
531<code>'unhandledRejection'</code>. The latter is only used in conjunction with the
532<a href="cli.html#cli_unhandled_rejections_mode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> and
533an unhandled rejection.</li>
534</ul>
535<p>The <code>'uncaughtExceptionMonitor'</code> event is emitted before an
536<code>'uncaughtException'</code> event is emitted or a hook installed via
537<a href="#process_process_setuncaughtexceptioncapturecallback_fn"><code>process.setUncaughtExceptionCaptureCallback()</code></a> is called.</p>
538<p>Installing an <code>'uncaughtExceptionMonitor'</code> listener does not change the behavior
539once an <code>'uncaughtException'</code> event is emitted. The process will
540still crash if no <code>'uncaughtException'</code> listener is installed.</p>
541<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtExceptionMonitor'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> {
542  <span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin);
543});
544
545<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
546<span class="hljs-title function_">nonexistentFunc</span>();
547<span class="hljs-comment">// Still crashes Node.js</span></code></pre>
548<h4>Event: <code>'unhandledRejection'</code><span><a class="mark" href="#process_event_unhandledrejection" id="process_event_unhandledrejection">#</a></span></h4>
549<div class="api_metadata">
550<details class="changelog"><summary>History</summary>
551<table>
552<tbody><tr><th>Version</th><th>Changes</th></tr>
553<tr><td>v7.0.0</td>
554<td><p>Not handling <code>Promise</code> rejections is deprecated.</p></td></tr>
555<tr><td>v6.6.0</td>
556<td><p>Unhandled <code>Promise</code> rejections will now emit a process warning.</p></td></tr>
557<tr><td>v1.4.1</td>
558<td><p><span>Added in: v1.4.1</span></p></td></tr>
559</tbody></table>
560</details>
561</div>
562<ul>
563<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The object with which the promise was rejected
564(typically an <a href="errors.html#errors_class_error"><code>Error</code></a> object).</li>
565<li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> The rejected promise.</li>
566</ul>
567<p>The <code>'unhandledRejection'</code> event is emitted whenever a <code>Promise</code> is rejected and
568no error handler is attached to the promise within a turn of the event loop.
569When programming with Promises, exceptions are encapsulated as "rejected
570promises". Rejections can be caught and handled using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch"><code>promise.catch()</code></a> and
571are propagated through a <code>Promise</code> chain. The <code>'unhandledRejection'</code> event is
572useful for detecting and keeping track of promises that were rejected whose
573rejections have not yet been handled.</p>
574<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> {
575  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Unhandled Rejection at:'</span>, promise, <span class="hljs-string">'reason:'</span>, reason);
576  <span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span>
577});
578
579somePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
580  <span class="hljs-keyword">return</span> <span class="hljs-title function_">reportToUser</span>(<span class="hljs-variable constant_">JSON</span>.<span class="hljs-title function_">pasre</span>(res)); <span class="hljs-comment">// Note the typo (`pasre`)</span>
581}); <span class="hljs-comment">// No `.catch()` or `.then()`</span></code></pre>
582<p>The following will also trigger the <code>'unhandledRejection'</code> event to be
583emitted:</p>
584<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) {
585  <span class="hljs-comment">// Initially set the loaded status to a rejected promise</span>
586  <span class="hljs-variable language_">this</span>.<span class="hljs-property">loaded</span> = <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Resource not yet loaded!'</span>));
587}
588
589<span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>();
590<span class="hljs-comment">// no .catch or .then on resource.loaded for at least a turn</span></code></pre>
591<p>In this example case, it is possible to track the rejection as a developer error
592as would typically be the case for other <code>'unhandledRejection'</code> events. To
593address such failures, a non-operational
594<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch"><code>.catch(() => { })</code></a> handler may be attached to
595<code>resource.loaded</code>, which would prevent the <code>'unhandledRejection'</code> event from
596being emitted.</p>
597<h4>Event: <code>'warning'</code><span><a class="mark" href="#process_event_warning" id="process_event_warning">#</a></span></h4>
598<div class="api_metadata">
599<span>Added in: v6.0.0</span>
600</div>
601<ul>
602<li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> Key properties of the warning are:
603<ul>
604<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The name of the warning. <strong>Default:</strong> <code>'Warning'</code>.</li>
605<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A system-provided description of the warning.</li>
606<li><code>stack</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A stack trace to the location in the code where the warning
607was issued.</li>
608</ul>
609</li>
610</ul>
611<p>The <code>'warning'</code> event is emitted whenever Node.js emits a process warning.</p>
612<p>A process warning is similar to an error in that it describes exceptional
613conditions that are being brought to the user's attention. However, warnings
614are not part of the normal Node.js and JavaScript error handling flow.
615Node.js can emit warnings whenever it detects bad coding practices that could
616lead to sub-optimal application performance, bugs, or security vulnerabilities.</p>
617<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
618  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);    <span class="hljs-comment">// Print the warning name</span>
619  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-comment">// Print the warning message</span>
620  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);   <span class="hljs-comment">// Print the stack trace</span>
621});</code></pre>
622<p>By default, Node.js will print process warnings to <code>stderr</code>. The <code>--no-warnings</code>
623command-line option can be used to suppress the default console output but the
624<code>'warning'</code> event will still be emitted by the <code>process</code> object.</p>
625<p>The following example illustrates the warning that is printed to <code>stderr</code> when
626too many listeners have been added to an event:</p>
627<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">node</span>
628<span class="hljs-meta">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
629<span class="hljs-meta">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
630<span class="hljs-meta">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
631<span class="hljs-meta">> </span><span class="language-bash">(node:38638) MaxListenersExceededWarning: Possible EventEmitter memory leak</span>
632detected. 2 foo listeners added. Use emitter.setMaxListeners() to increase limit</code></pre>
633<p>In contrast, the following example turns off the default warning output and
634adds a custom handler to the <code>'warning'</code> event:</p>
635<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">node --no-warnings</span>
636<span class="hljs-meta">> </span><span class="language-bash">const p = process.on(<span class="hljs-string">'warning'</span>, (warning) => console.warn(<span class="hljs-string">'Do not do that!'</span>));</span>
637<span class="hljs-meta">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
638<span class="hljs-meta">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
639<span class="hljs-meta">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
640<span class="hljs-meta">> </span><span class="language-bash">Do not <span class="hljs-keyword">do</span> that!</span></code></pre>
641<p>The <code>--trace-warnings</code> command-line option can be used to have the default
642console output for warnings include the full stack trace of the warning.</p>
643<p>Launching Node.js using the <code>--throw-deprecation</code> command-line flag will
644cause custom deprecation warnings to be thrown as exceptions.</p>
645<p>Using the <code>--trace-deprecation</code> command-line flag will cause the custom
646deprecation to be printed to <code>stderr</code> along with the stack trace.</p>
647<p>Using the <code>--no-deprecation</code> command-line flag will suppress all reporting
648of the custom deprecation.</p>
649<p>The <code>*-deprecation</code> command-line flags only affect warnings that use the name
650<code>'DeprecationWarning'</code>.</p>
651<h4>Event: <code>'worker'</code><span><a class="mark" href="#process_event_worker" id="process_event_worker">#</a></span></h4>
652<div class="api_metadata">
653<span>Added in: v14.18.0</span>
654</div>
655<ul>
656<li><code>worker</code> <a href="worker_threads.html#worker_threads_class_worker" class="type">&#x3C;Worker></a> The <a href="worker_threads.html#worker_threads_class_worker" class="type">&#x3C;Worker></a> that was created.</li>
657</ul>
658<p>The <code>'worker'</code> event is emitted after a new <a href="worker_threads.html#worker_threads_class_worker" class="type">&#x3C;Worker></a> thread has been created.</p>
659<h5>Emitting custom warnings<span><a class="mark" href="#process_emitting_custom_warnings" id="process_emitting_custom_warnings">#</a></span></h5>
660<p>See the <a href="#process_process_emitwarning_warning_type_code_ctor"><code>process.emitWarning()</code></a> method for issuing
661custom or application-specific warnings.</p>
662<h5>Node.js warning names<span><a class="mark" href="#process_node_js_warning_names" id="process_node_js_warning_names">#</a></span></h5>
663<p>There are no strict guidelines for warning types (as identified by the <code>name</code>
664property) emitted by Node.js. New types of warnings can be added at any time.
665A few of the warning types that are most common include:</p>
666<ul>
667<li><code>'DeprecationWarning'</code> - Indicates use of a deprecated Node.js API or feature.
668Such warnings must include a <code>'code'</code> property identifying the
669<a href="deprecations.html">deprecation code</a>.</li>
670<li><code>'ExperimentalWarning'</code> - Indicates use of an experimental Node.js API or
671feature. Such features must be used with caution as they may change at any
672time and are not subject to the same strict semantic-versioning and long-term
673support policies as supported features.</li>
674<li><code>'MaxListenersExceededWarning'</code> - Indicates that too many listeners for a
675given event have been registered on either an <code>EventEmitter</code> or <code>EventTarget</code>.
676This is often an indication of a memory leak.</li>
677<li><code>'TimeoutOverflowWarning'</code> - Indicates that a numeric value that cannot fit
678within a 32-bit signed integer has been provided to either the <code>setTimeout()</code>
679or <code>setInterval()</code> functions.</li>
680<li><code>'UnsupportedWarning'</code> - Indicates use of an unsupported option or feature
681that will be ignored rather than treated as an error. One example is use of
682the HTTP response status message when using the HTTP/2 compatibility API.</li>
683</ul>
684<h4>Signal events<span><a class="mark" href="#process_signal_events" id="process_signal_events">#</a></span></h4>
685
686
687<p>Signal events will be emitted when the Node.js process receives a signal. Please
688refer to <a href="http://man7.org/linux/man-pages/man7/signal.7.html"><code>signal(7)</code></a> for a listing of standard POSIX signal names such as
689<code>'SIGINT'</code>, <code>'SIGHUP'</code>, etc.</p>
690<p>Signals are not available on <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
691<p>The signal handler will receive the signal's name (<code>'SIGINT'</code>,
692<code>'SIGTERM'</code>, etc.) as the first argument.</p>
693<p>The name of each event will be the uppercase common name for the signal (e.g.
694<code>'SIGINT'</code> for <code>SIGINT</code> signals).</p>
695<pre><code class="language-js"><span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span>
696process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>();
697
698process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> {
699  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Received SIGINT. Press Control-D to exit.'</span>);
700});
701
702<span class="hljs-comment">// Using a single function to handle multiple signals</span>
703<span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) {
704  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Received <span class="hljs-subst">${signal}</span>`</span>);
705}
706
707process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle);
708process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGTERM'</span>, handle);</code></pre>
709<ul>
710<li><code>'SIGUSR1'</code> is reserved by Node.js to start the <a href="debugger.html">debugger</a>. It's possible to
711install a listener but doing so might interfere with the debugger.</li>
712<li><code>'SIGTERM'</code> and <code>'SIGINT'</code> have default handlers on non-Windows platforms that
713reset the terminal mode before exiting with code <code>128 + signal number</code>. If one
714of these signals has a listener installed, its default behavior will be
715removed (Node.js will no longer exit).</li>
716<li><code>'SIGPIPE'</code> is ignored by default. It can have a listener installed.</li>
717<li><code>'SIGHUP'</code> is generated on Windows when the console window is closed, and on
718other platforms under various similar conditions. See <a href="http://man7.org/linux/man-pages/man7/signal.7.html"><code>signal(7)</code></a>. It can have a
719listener installed, however Node.js will be unconditionally terminated by
720Windows about 10 seconds later. On non-Windows platforms, the default
721behavior of <code>SIGHUP</code> is to terminate Node.js, but once a listener has been
722installed its default behavior will be removed.</li>
723<li><code>'SIGTERM'</code> is not supported on Windows, it can be listened on.</li>
724<li><code>'SIGINT'</code> from the terminal is supported on all platforms, and can usually be
725generated with <kbd>Ctrl</kbd>+<kbd>C</kbd> (though this may be configurable).
726It is not generated when <a href="tty.html#tty_readstream_setrawmode_mode">terminal raw mode</a> is enabled and
727<kbd>Ctrl</kbd>+<kbd>C</kbd> is used.</li>
728<li><code>'SIGBREAK'</code> is delivered on Windows when <kbd>Ctrl</kbd>+<kbd>Break</kbd> is
729pressed. On non-Windows platforms, it can be listened on, but there is no way
730to send or generate it.</li>
731<li><code>'SIGWINCH'</code> is delivered when the console has been resized. On Windows, this
732will only happen on write to the console when the cursor is being moved, or
733when a readable tty is used in raw mode.</li>
734<li><code>'SIGKILL'</code> cannot have a listener installed, it will unconditionally
735terminate Node.js on all platforms.</li>
736<li><code>'SIGSTOP'</code> cannot have a listener installed.</li>
737<li><code>'SIGBUS'</code>, <code>'SIGFPE'</code>, <code>'SIGSEGV'</code> and <code>'SIGILL'</code>, when not raised
738artificially using <a href="http://man7.org/linux/man-pages/man2/kill.2.html"><code>kill(2)</code></a>, inherently leave the process in a state from
739which it is not safe to call JS listeners. Doing so might cause the process
740to stop responding.</li>
741<li><code>0</code> can be sent to test for the existence of a process, it has no effect if
742the process exists, but will throw an error if the process does not exist.</li>
743</ul>
744<p>Windows does not support signals so has no equivalent to termination by signal,
745but Node.js offers some emulation with <a href="#process_process_kill_pid_signal"><code>process.kill()</code></a>, and
746<a href="child_process.html#child_process_subprocess_kill_signal"><code>subprocess.kill()</code></a>:</p>
747<ul>
748<li>Sending <code>SIGINT</code>, <code>SIGTERM</code>, and <code>SIGKILL</code> will cause the unconditional
749termination of the target process, and afterwards, subprocess will report that
750the process was terminated by signal.</li>
751<li>Sending signal <code>0</code> can be used as a platform independent way to test for the
752existence of a process.</li>
753</ul>
754</section><section><h3><code>process.abort()</code><span><a class="mark" href="#process_process_abort" id="process_process_abort">#</a></span></h3>
755<div class="api_metadata">
756<span>Added in: v0.7.0</span>
757</div>
758<p>The <code>process.abort()</code> method causes the Node.js process to exit immediately and
759generate a core file.</p>
760<p>This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
761</section><section><h3><code>process.allowedNodeEnvironmentFlags</code><span><a class="mark" href="#process_process_allowednodeenvironmentflags" id="process_process_allowednodeenvironmentflags">#</a></span></h3>
762<div class="api_metadata">
763<span>Added in: v10.10.0</span>
764</div>
765<ul>
766<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set" class="type">&#x3C;Set></a></li>
767</ul>
768<p>The <code>process.allowedNodeEnvironmentFlags</code> property is a special,
769read-only <code>Set</code> of flags allowable within the <a href="cli.html#cli_node_options_options"><code>NODE_OPTIONS</code></a>
770environment variable.</p>
771<p><code>process.allowedNodeEnvironmentFlags</code> extends <code>Set</code>, but overrides
772<code>Set.prototype.has</code> to recognize several different possible flag
773representations. <code>process.allowedNodeEnvironmentFlags.has()</code> will
774return <code>true</code> in the following cases:</p>
775<ul>
776<li>Flags may omit leading single (<code>-</code>) or double (<code>--</code>) dashes; e.g.,
777<code>inspect-brk</code> for <code>--inspect-brk</code>, or <code>r</code> for <code>-r</code>.</li>
778<li>Flags passed through to V8 (as listed in <code>--v8-options</code>) may replace
779one or more <em>non-leading</em> dashes for an underscore, or vice-versa;
780e.g., <code>--perf_basic_prof</code>, <code>--perf-basic-prof</code>, <code>--perf_basic-prof</code>,
781etc.</li>
782<li>Flags may contain one or more equals (<code>=</code>) characters; all
783characters after and including the first equals will be ignored;
784e.g., <code>--stack-trace-limit=100</code>.</li>
785<li>Flags <em>must</em> be allowable within <a href="cli.html#cli_node_options_options"><code>NODE_OPTIONS</code></a>.</li>
786</ul>
787<p>When iterating over <code>process.allowedNodeEnvironmentFlags</code>, flags will
788appear only <em>once</em>; each will begin with one or more dashes. Flags
789passed through to V8 will contain underscores instead of non-leading
790dashes:</p>
791<pre><code class="language-js">process.<span class="hljs-property">allowedNodeEnvironmentFlags</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> {
792  <span class="hljs-comment">// -r</span>
793  <span class="hljs-comment">// --inspect-brk</span>
794  <span class="hljs-comment">// --abort_on_uncaught_exception</span>
795  <span class="hljs-comment">// ...</span>
796});</code></pre>
797<p>The methods <code>add()</code>, <code>clear()</code>, and <code>delete()</code> of
798<code>process.allowedNodeEnvironmentFlags</code> do nothing, and will fail
799silently.</p>
800<p>If Node.js was compiled <em>without</em> <a href="cli.html#cli_node_options_options"><code>NODE_OPTIONS</code></a> support (shown in
801<a href="#process_process_config"><code>process.config</code></a>), <code>process.allowedNodeEnvironmentFlags</code> will
802contain what <em>would have</em> been allowable.</p>
803</section><section><h3><code>process.arch</code><span><a class="mark" href="#process_process_arch" id="process_process_arch">#</a></span></h3>
804<div class="api_metadata">
805<span>Added in: v0.5.0</span>
806</div>
807<ul>
808<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
809</ul>
810<p>The operating system CPU architecture for which the Node.js binary was compiled.
811Possible values are: <code>'arm'</code>, <code>'arm64'</code>, <code>'ia32'</code>, <code>'mips'</code>,<code>'mipsel'</code>, <code>'ppc'</code>,
812<code>'ppc64'</code>, <code>'s390'</code>, <code>'s390x'</code>, <code>'x32'</code>, and <code>'x64'</code>.</p>
813<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This processor architecture is <span class="hljs-subst">${process.arch}</span>`</span>);</code></pre>
814</section><section><h3><code>process.argv</code><span><a class="mark" href="#process_process_argv" id="process_process_argv">#</a></span></h3>
815<div class="api_metadata">
816<span>Added in: v0.1.27</span>
817</div>
818<ul>
819<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
820</ul>
821<p>The <code>process.argv</code> property returns an array containing the command-line
822arguments passed when the Node.js process was launched. The first element will
823be <a href="#process_process_execpath"><code>process.execPath</code></a>. See <code>process.argv0</code> if access to the original value
824of <code>argv[0]</code> is needed. The second element will be the path to the JavaScript
825file being executed. The remaining elements will be any additional command-line
826arguments.</p>
827<p>For example, assuming the following script for <code>process-args.js</code>:</p>
828<pre><code class="language-js"><span class="hljs-comment">// print process.argv</span>
829process.<span class="hljs-property">argv</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> {
830  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`<span class="hljs-subst">${index}</span>: <span class="hljs-subst">${val}</span>`</span>);
831});</code></pre>
832<p>Launching the Node.js process as:</p>
833<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">node process-args.js one two=three four</span></code></pre>
834<p>Would generate the output:</p>
835<pre><code class="language-text">0: /usr/local/bin/node
8361: /Users/mjr/work/node/process-args.js
8372: one
8383: two=three
8394: four</code></pre>
840</section><section><h3><code>process.argv0</code><span><a class="mark" href="#process_process_argv0" id="process_process_argv0">#</a></span></h3>
841<div class="api_metadata">
842<span>Added in: v6.4.0</span>
843</div>
844<ul>
845<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
846</ul>
847<p>The <code>process.argv0</code> property stores a read-only copy of the original value of
848<code>argv[0]</code> passed when Node.js starts.</p>
849<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">bash -c <span class="hljs-string">'exec -a customArgv0 ./node'</span></span>
850<span class="hljs-meta">> </span><span class="language-bash">process.argv[0]</span>
851'/Volumes/code/external/node/out/Release/node'
852<span class="hljs-meta">> </span><span class="language-bash">process.argv0</span>
853'customArgv0'</code></pre>
854</section><section><h3><code>process.channel</code><span><a class="mark" href="#process_process_channel" id="process_process_channel">#</a></span></h3>
855<div class="api_metadata">
856<details class="changelog"><summary>History</summary>
857<table>
858<tbody><tr><th>Version</th><th>Changes</th></tr>
859<tr><td>v14.0.0</td>
860<td><p>The object no longer accidentally exposes native C++ bindings.</p></td></tr>
861<tr><td>v7.1.0</td>
862<td><p><span>Added in: v7.1.0</span></p></td></tr>
863</tbody></table>
864</details>
865</div>
866<ul>
867<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
868</ul>
869<p>If the Node.js process was spawned with an IPC channel (see the
870<a href="child_process.html">Child Process</a> documentation), the <code>process.channel</code>
871property is a reference to the IPC channel. If no IPC channel exists, this
872property is <code>undefined</code>.</p>
873<h4><code>process.channel.ref()</code><span><a class="mark" href="#process_process_channel_ref" id="process_process_channel_ref">#</a></span></h4>
874<div class="api_metadata">
875<span>Added in: v7.1.0</span>
876</div>
877<p>This method makes the IPC channel keep the event loop of the process
878running if <code>.unref()</code> has been called before.</p>
879<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
880listeners on the <code>process</code> object. However, this method can be used to
881explicitly request a specific behavior.</p>
882<h4><code>process.channel.unref()</code><span><a class="mark" href="#process_process_channel_unref" id="process_process_channel_unref">#</a></span></h4>
883<div class="api_metadata">
884<span>Added in: v7.1.0</span>
885</div>
886<p>This method makes the IPC channel not keep the event loop of the process
887running, and lets it finish even while the channel is open.</p>
888<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
889listeners on the <code>process</code> object. However, this method can be used to
890explicitly request a specific behavior.</p>
891</section><section><h3><code>process.chdir(directory)</code><span><a class="mark" href="#process_process_chdir_directory" id="process_process_chdir_directory">#</a></span></h3>
892<div class="api_metadata">
893<span>Added in: v0.1.17</span>
894</div>
895<ul>
896<li><code>directory</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
897</ul>
898<p>The <code>process.chdir()</code> method changes the current working directory of the
899Node.js process or throws an exception if doing so fails (for instance, if
900the specified <code>directory</code> does not exist).</p>
901<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Starting directory: <span class="hljs-subst">${process.cwd()}</span>`</span>);
902<span class="hljs-keyword">try</span> {
903  process.<span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>);
904  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New directory: <span class="hljs-subst">${process.cwd()}</span>`</span>);
905} <span class="hljs-keyword">catch</span> (err) {
906  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`chdir: <span class="hljs-subst">${err}</span>`</span>);
907}</code></pre>
908<p>This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
909</section><section><h3><code>process.config</code><span><a class="mark" href="#process_process_config" id="process_process_config">#</a></span></h3>
910<div class="api_metadata">
911<span>Added in: v0.7.7</span>
912</div>
913<ul>
914<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
915</ul>
916<p>The <code>process.config</code> property returns an <code>Object</code> containing the JavaScript
917representation of the configure options used to compile the current Node.js
918executable. This is the same as the <code>config.gypi</code> file that was produced when
919running the <code>./configure</code> script.</p>
920<p>An example of the possible output looks like:</p>
921<!-- eslint-skip -->
922<pre><code class="language-js">{
923  <span class="hljs-attr">target_defaults</span>:
924   { <span class="hljs-attr">cflags</span>: [],
925     <span class="hljs-attr">default_configuration</span>: <span class="hljs-string">'Release'</span>,
926     <span class="hljs-attr">defines</span>: [],
927     <span class="hljs-attr">include_dirs</span>: [],
928     <span class="hljs-attr">libraries</span>: [] },
929  <span class="hljs-attr">variables</span>:
930   {
931     <span class="hljs-attr">host_arch</span>: <span class="hljs-string">'x64'</span>,
932     <span class="hljs-attr">napi_build_version</span>: <span class="hljs-number">5</span>,
933     <span class="hljs-attr">node_install_npm</span>: <span class="hljs-string">'true'</span>,
934     <span class="hljs-attr">node_prefix</span>: <span class="hljs-string">''</span>,
935     <span class="hljs-attr">node_shared_cares</span>: <span class="hljs-string">'false'</span>,
936     <span class="hljs-attr">node_shared_http_parser</span>: <span class="hljs-string">'false'</span>,
937     <span class="hljs-attr">node_shared_libuv</span>: <span class="hljs-string">'false'</span>,
938     <span class="hljs-attr">node_shared_zlib</span>: <span class="hljs-string">'false'</span>,
939     <span class="hljs-attr">node_use_dtrace</span>: <span class="hljs-string">'false'</span>,
940     <span class="hljs-attr">node_use_openssl</span>: <span class="hljs-string">'true'</span>,
941     <span class="hljs-attr">node_shared_openssl</span>: <span class="hljs-string">'false'</span>,
942     <span class="hljs-attr">strict_aliasing</span>: <span class="hljs-string">'true'</span>,
943     <span class="hljs-attr">target_arch</span>: <span class="hljs-string">'x64'</span>,
944     <span class="hljs-attr">v8_use_snapshot</span>: <span class="hljs-number">1</span>
945   }
946}</code></pre>
947<p>The <code>process.config</code> property is <strong>not</strong> read-only and there are existing
948modules in the ecosystem that are known to extend, modify, or entirely replace
949the value of <code>process.config</code>.</p>
950</section><section><h3><code>process.connected</code><span><a class="mark" href="#process_process_connected" id="process_process_connected">#</a></span></h3>
951<div class="api_metadata">
952<span>Added in: v0.7.2</span>
953</div>
954<ul>
955<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
956</ul>
957<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
958and <a href="cluster.html">Cluster</a> documentation), the <code>process.connected</code> property will return
959<code>true</code> so long as the IPC channel is connected and will return <code>false</code> after
960<code>process.disconnect()</code> is called.</p>
961<p>Once <code>process.connected</code> is <code>false</code>, it is no longer possible to send messages
962over the IPC channel using <code>process.send()</code>.</p>
963</section><section><h3><code>process.cpuUsage([previousValue])</code><span><a class="mark" href="#process_process_cpuusage_previousvalue" id="process_process_cpuusage_previousvalue">#</a></span></h3>
964<div class="api_metadata">
965<span>Added in: v6.1.0</span>
966</div>
967<ul>
968<li><code>previousValue</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> A previous return value from calling
969<code>process.cpuUsage()</code></li>
970<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
971<ul>
972<li><code>user</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
973<li><code>system</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
974</ul>
975</li>
976</ul>
977<p>The <code>process.cpuUsage()</code> method returns the user and system CPU time usage of
978the current process, in an object with properties <code>user</code> and <code>system</code>, whose
979values are microsecond values (millionth of a second). These values measure time
980spent in user and system code respectively, and may end up being greater than
981actual elapsed time if multiple CPU cores are performing work for this process.</p>
982<p>The result of a previous call to <code>process.cpuUsage()</code> can be passed as the
983argument to the function, to get a diff reading.</p>
984<pre><code class="language-js"><span class="hljs-keyword">const</span> startUsage = process.<span class="hljs-title function_">cpuUsage</span>();
985<span class="hljs-comment">// { user: 38579, system: 6986 }</span>
986
987<span class="hljs-comment">// spin the CPU for 500 milliseconds</span>
988<span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>();
989<span class="hljs-keyword">while</span> (<span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>() - now &#x3C; <span class="hljs-number">500</span>);
990
991<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">cpuUsage</span>(startUsage));
992<span class="hljs-comment">// { user: 514883, system: 11226 }</span></code></pre>
993</section><section><h3><code>process.cwd()</code><span><a class="mark" href="#process_process_cwd" id="process_process_cwd">#</a></span></h3>
994<div class="api_metadata">
995<span>Added in: v0.1.8</span>
996</div>
997<ul>
998<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
999</ul>
1000<p>The <code>process.cwd()</code> method returns the current working directory of the Node.js
1001process.</p>
1002<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current directory: <span class="hljs-subst">${process.cwd()}</span>`</span>);</code></pre>
1003</section><section><h3><code>process.debugPort</code><span><a class="mark" href="#process_process_debugport" id="process_process_debugport">#</a></span></h3>
1004<div class="api_metadata">
1005<span>Added in: v0.7.2</span>
1006</div>
1007<ul>
1008<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1009</ul>
1010<p>The port used by the Node.js debugger when enabled.</p>
1011<pre><code class="language-js">process.<span class="hljs-property">debugPort</span> = <span class="hljs-number">5858</span>;</code></pre>
1012</section><section><h3><code>process.disconnect()</code><span><a class="mark" href="#process_process_disconnect" id="process_process_disconnect">#</a></span></h3>
1013<div class="api_metadata">
1014<span>Added in: v0.7.2</span>
1015</div>
1016<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
1017and <a href="cluster.html">Cluster</a> documentation), the <code>process.disconnect()</code> method will close the
1018IPC channel to the parent process, allowing the child process to exit gracefully
1019once there are no other connections keeping it alive.</p>
1020<p>The effect of calling <code>process.disconnect()</code> is the same as calling
1021<a href="child_process.html#child_process_subprocess_disconnect"><code>ChildProcess.disconnect()</code></a> from the parent process.</p>
1022<p>If the Node.js process was not spawned with an IPC channel,
1023<code>process.disconnect()</code> will be <code>undefined</code>.</p>
1024</section><section><h3><code>process.dlopen(module, filename[, flags])</code><span><a class="mark" href="#process_process_dlopen_module_filename_flags" id="process_process_dlopen_module_filename_flags">#</a></span></h3>
1025<div class="api_metadata">
1026<details class="changelog"><summary>History</summary>
1027<table>
1028<tbody><tr><th>Version</th><th>Changes</th></tr>
1029<tr><td>v9.0.0</td>
1030<td><p>Added support for the <code>flags</code> argument.</p></td></tr>
1031<tr><td>v0.1.16</td>
1032<td><p><span>Added in: v0.1.16</span></p></td></tr>
1033</tbody></table>
1034</details>
1035</div>
1036<ul>
1037<li><code>module</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1038<li><code>filename</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1039<li><code>flags</code> <a href="os.html#os_dlopen_constants" class="type">&#x3C;os.constants.dlopen></a> <strong>Default:</strong> <code>os.constants.dlopen.RTLD_LAZY</code></li>
1040</ul>
1041<p>The <code>process.dlopen()</code> method allows dynamically loading shared objects. It is
1042primarily used by <code>require()</code> to load C++ Addons, and should not be used
1043directly, except in special cases. In other words, <a href="globals.html#globals_require"><code>require()</code></a> should be
1044preferred over <code>process.dlopen()</code> unless there are specific reasons such as
1045custom dlopen flags or loading from ES modules.</p>
1046<p>The <code>flags</code> argument is an integer that allows to specify dlopen
1047behavior. See the <a href="os.html#os_dlopen_constants"><code>os.constants.dlopen</code></a> documentation for details.</p>
1048<p>An important requirement when calling <code>process.dlopen()</code> is that the <code>module</code>
1049instance must be passed. Functions exported by the C++ Addon are then
1050accessible via <code>module.exports</code>.</p>
1051<p>The example below shows how to load a C++ Addon, named <code>local.node</code>,
1052that exports a <code>foo</code> function. All the symbols are loaded before
1053the call returns, by passing the <code>RTLD_NOW</code> constant. In this example
1054the constant is assumed to be available.</p>
1055<pre><code class="language-js"><span class="hljs-keyword">const</span> os = <span class="hljs-built_in">require</span>(<span class="hljs-string">'os'</span>);
1056<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">'path'</span>);
1057<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} };
1058process.<span class="hljs-title function_">dlopen</span>(<span class="hljs-variable language_">module</span>, path.<span class="hljs-title function_">join</span>(__dirname, <span class="hljs-string">'local.node'</span>),
1059               os.<span class="hljs-property">constants</span>.<span class="hljs-property">dlopen</span>.<span class="hljs-property">RTLD_NOW</span>);
1060<span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span>.<span class="hljs-title function_">foo</span>();</code></pre>
1061</section><section><h3><code>process.emitWarning(warning[, options])</code><span><a class="mark" href="#process_process_emitwarning_warning_options" id="process_process_emitwarning_warning_options">#</a></span></h3>
1062<div class="api_metadata">
1063<span>Added in: v8.0.0</span>
1064</div>
1065<ul>
1066<li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> The warning to emit.</li>
1067<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1068<ul>
1069<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> When <code>warning</code> is a <code>String</code>, <code>type</code> is the name to use
1070for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
1071<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A unique identifier for the warning instance being emitted.</li>
1072<li><code>ctor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> When <code>warning</code> is a <code>String</code>, <code>ctor</code> is an optional
1073function used to limit the generated stack trace. <strong>Default:</strong>
1074<code>process.emitWarning</code>.</li>
1075<li><code>detail</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Additional text to include with the error.</li>
1076</ul>
1077</li>
1078</ul>
1079<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
1080specific process warnings. These can be listened for by adding a handler to the
1081<a href="#process_event_warning"><code>'warning'</code></a> event.</p>
1082<pre><code class="language-js"><span class="hljs-comment">// Emit a warning with a code and additional detail.</span>
1083process.<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, {
1084  <span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>,
1085  <span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>
1086});
1087<span class="hljs-comment">// Emits:</span>
1088<span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span>
1089<span class="hljs-comment">// This is some additional information</span></code></pre>
1090<p>In this example, an <code>Error</code> object is generated internally by
1091<code>process.emitWarning()</code> and passed through to the
1092<a href="#process_event_warning"><code>'warning'</code></a> handler.</p>
1093<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1094  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);    <span class="hljs-comment">// 'Warning'</span>
1095  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-comment">// 'Something happened!'</span>
1096  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);    <span class="hljs-comment">// 'MY_WARNING'</span>
1097  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);   <span class="hljs-comment">// Stack trace</span>
1098  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">detail</span>);  <span class="hljs-comment">// 'This is some additional information'</span>
1099});</code></pre>
1100<p>If <code>warning</code> is passed as an <code>Error</code> object, the <code>options</code> argument is ignored.</p>
1101</section><section><h3><code>process.emitWarning(warning[, type[, code]][, ctor])</code><span><a class="mark" href="#process_process_emitwarning_warning_type_code_ctor" id="process_process_emitwarning_warning_type_code_ctor">#</a></span></h3>
1102<div class="api_metadata">
1103<span>Added in: v6.0.0</span>
1104</div>
1105<ul>
1106<li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> The warning to emit.</li>
1107<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> When <code>warning</code> is a <code>String</code>, <code>type</code> is the name to use
1108for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
1109<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A unique identifier for the warning instance being emitted.</li>
1110<li><code>ctor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> When <code>warning</code> is a <code>String</code>, <code>ctor</code> is an optional
1111function used to limit the generated stack trace. <strong>Default:</strong>
1112<code>process.emitWarning</code>.</li>
1113</ul>
1114<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
1115specific process warnings. These can be listened for by adding a handler to the
1116<a href="#process_event_warning"><code>'warning'</code></a> event.</p>
1117<pre><code class="language-js"><span class="hljs-comment">// Emit a warning using a string.</span>
1118process.<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>);
1119<span class="hljs-comment">// Emits: (node: 56338) Warning: Something happened!</span></code></pre>
1120<pre><code class="language-js"><span class="hljs-comment">// Emit a warning using a string and a type.</span>
1121process.<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>);
1122<span class="hljs-comment">// Emits: (node:56338) CustomWarning: Something Happened!</span></code></pre>
1123<pre><code class="language-js">process.<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, <span class="hljs-string">'CustomWarning'</span>, <span class="hljs-string">'WARN001'</span>);
1124<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code></pre>
1125<p>In each of the previous examples, an <code>Error</code> object is generated internally by
1126<code>process.emitWarning()</code> and passed through to the <a href="#process_event_warning"><code>'warning'</code></a>
1127handler.</p>
1128<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1129  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);
1130  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>);
1131  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);
1132  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);
1133});</code></pre>
1134<p>If <code>warning</code> is passed as an <code>Error</code> object, it will be passed through to the
1135<code>'warning'</code> event handler unmodified (and the optional <code>type</code>,
1136<code>code</code> and <code>ctor</code> arguments will be ignored):</p>
1137<pre><code class="language-js"><span class="hljs-comment">// Emit a warning using an Error object.</span>
1138<span class="hljs-keyword">const</span> myWarning = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Something happened!'</span>);
1139<span class="hljs-comment">// Use the Error name property to specify the type name</span>
1140myWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>;
1141myWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>;
1142
1143process.<span class="hljs-title function_">emitWarning</span>(myWarning);
1144<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code></pre>
1145<p>A <code>TypeError</code> is thrown if <code>warning</code> is anything other than a string or <code>Error</code>
1146object.</p>
1147<p>While process warnings use <code>Error</code> objects, the process warning
1148mechanism is <strong>not</strong> a replacement for normal error handling mechanisms.</p>
1149<p>The following additional handling is implemented if the warning <code>type</code> is
1150<code>'DeprecationWarning'</code>:</p>
1151<ul>
1152<li>If the <code>--throw-deprecation</code> command-line flag is used, the deprecation
1153warning is thrown as an exception rather than being emitted as an event.</li>
1154<li>If the <code>--no-deprecation</code> command-line flag is used, the deprecation
1155warning is suppressed.</li>
1156<li>If the <code>--trace-deprecation</code> command-line flag is used, the deprecation
1157warning is printed to <code>stderr</code> along with the full stack trace.</li>
1158</ul>
1159<h4>Avoiding duplicate warnings<span><a class="mark" href="#process_avoiding_duplicate_warnings" id="process_avoiding_duplicate_warnings">#</a></span></h4>
1160<p>As a best practice, warnings should be emitted only once per process. To do
1161so, it is recommended to place the <code>emitWarning()</code> behind a simple boolean
1162flag as illustrated in the example below:</p>
1163<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) {
1164  <span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) {
1165    emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>;
1166    process.<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>);
1167  }
1168}
1169<span class="hljs-title function_">emitMyWarning</span>();
1170<span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span>
1171<span class="hljs-title function_">emitMyWarning</span>();
1172<span class="hljs-comment">// Emits nothing</span></code></pre>
1173</section><section><h3><code>process.env</code><span><a class="mark" href="#process_process_env" id="process_process_env">#</a></span></h3>
1174<div class="api_metadata">
1175<details class="changelog"><summary>History</summary>
1176<table>
1177<tbody><tr><th>Version</th><th>Changes</th></tr>
1178<tr><td>v11.14.0</td>
1179<td><p>Worker threads will now use a copy of the parent thread’s <code>process.env</code> by default, configurable through the <code>env</code> option of the <code>Worker</code> constructor.</p></td></tr>
1180<tr><td>v10.0.0</td>
1181<td><p>Implicit conversion of variable value to string is deprecated.</p></td></tr>
1182<tr><td>v0.1.27</td>
1183<td><p><span>Added in: v0.1.27</span></p></td></tr>
1184</tbody></table>
1185</details>
1186</div>
1187<ul>
1188<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1189</ul>
1190<p>The <code>process.env</code> property returns an object containing the user environment.
1191See <a href="http://man7.org/linux/man-pages/man7/environ.7.html"><code>environ(7)</code></a>.</p>
1192<p>An example of this object looks like:</p>
1193<!-- eslint-skip -->
1194<pre><code class="language-js">{
1195  <span class="hljs-attr">TERM</span>: <span class="hljs-string">'xterm-256color'</span>,
1196  <span class="hljs-attr">SHELL</span>: <span class="hljs-string">'/usr/local/bin/bash'</span>,
1197  <span class="hljs-attr">USER</span>: <span class="hljs-string">'maciej'</span>,
1198  <span class="hljs-attr">PATH</span>: <span class="hljs-string">'~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'</span>,
1199  <span class="hljs-attr">PWD</span>: <span class="hljs-string">'/Users/maciej'</span>,
1200  <span class="hljs-attr">EDITOR</span>: <span class="hljs-string">'vim'</span>,
1201  <span class="hljs-attr">SHLVL</span>: <span class="hljs-string">'1'</span>,
1202  <span class="hljs-attr">HOME</span>: <span class="hljs-string">'/Users/maciej'</span>,
1203  <span class="hljs-attr">LOGNAME</span>: <span class="hljs-string">'maciej'</span>,
1204  <span class="hljs-attr">_</span>: <span class="hljs-string">'/usr/local/bin/node'</span>
1205}</code></pre>
1206<p>It is possible to modify this object, but such modifications will not be
1207reflected outside the Node.js process, or (unless explicitly requested)
1208to other <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.
1209In other words, the following example would not work:</p>
1210<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">node -e <span class="hljs-string">'process.env.foo = "bar"'</span> &#x26;&#x26; <span class="hljs-built_in">echo</span> <span class="hljs-variable">$foo</span></span></code></pre>
1211<p>While the following will:</p>
1212<pre><code class="language-js">process.<span class="hljs-property">env</span>.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>;
1213<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-property">env</span>.<span class="hljs-property">foo</span>);</code></pre>
1214<p>Assigning a property on <code>process.env</code> will implicitly convert the value
1215to a string. <strong>This behavior is deprecated.</strong> Future versions of Node.js may
1216throw an error when the value is not a string, number, or boolean.</p>
1217<pre><code class="language-js">process.<span class="hljs-property">env</span>.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>;
1218<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-property">env</span>.<span class="hljs-property">test</span>);
1219<span class="hljs-comment">// => 'null'</span>
1220process.<span class="hljs-property">env</span>.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>;
1221<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-property">env</span>.<span class="hljs-property">test</span>);
1222<span class="hljs-comment">// => 'undefined'</span></code></pre>
1223<p>Use <code>delete</code> to delete a property from <code>process.env</code>.</p>
1224<pre><code class="language-js">process.<span class="hljs-property">env</span>.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
1225<span class="hljs-keyword">delete</span> process.<span class="hljs-property">env</span>.<span class="hljs-property">TEST</span>;
1226<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-property">env</span>.<span class="hljs-property">TEST</span>);
1227<span class="hljs-comment">// => undefined</span></code></pre>
1228<p>On Windows operating systems, environment variables are case-insensitive.</p>
1229<pre><code class="language-js">process.<span class="hljs-property">env</span>.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
1230<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-property">env</span>.<span class="hljs-property">test</span>);
1231<span class="hljs-comment">// => 1</span></code></pre>
1232<p>Unless explicitly specified when creating a <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> instance,
1233each <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> thread has its own copy of <code>process.env</code>, based on its
1234parent thread’s <code>process.env</code>, or whatever was specified as the <code>env</code> option
1235to the <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> constructor. Changes to <code>process.env</code> will not be visible
1236across <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads, and only the main thread can make changes that
1237are visible to the operating system or to native add-ons.</p>
1238</section><section><h3><code>process.execArgv</code><span><a class="mark" href="#process_process_execargv" id="process_process_execargv">#</a></span></h3>
1239<div class="api_metadata">
1240<span>Added in: v0.7.7</span>
1241</div>
1242<ul>
1243<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
1244</ul>
1245<p>The <code>process.execArgv</code> property returns the set of Node.js-specific command-line
1246options passed when the Node.js process was launched. These options do not
1247appear in the array returned by the <a href="#process_process_argv"><code>process.argv</code></a> property, and do not
1248include the Node.js executable, the name of the script, or any options following
1249the script name. These options are useful in order to spawn child processes with
1250the same execution environment as the parent.</p>
1251<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">node --harmony script.js --version</span></code></pre>
1252<p>Results in <code>process.execArgv</code>:</p>
1253<!-- eslint-disable semi -->
1254<pre><code class="language-js">[<span class="hljs-string">'--harmony'</span>]</code></pre>
1255<p>And <code>process.argv</code>:</p>
1256<!-- eslint-disable semi -->
1257<pre><code class="language-js">[<span class="hljs-string">'/usr/local/bin/node'</span>, <span class="hljs-string">'script.js'</span>, <span class="hljs-string">'--version'</span>]</code></pre>
1258<p>Refer to <a href="worker_threads.html#worker_threads_new_worker_filename_options"><code>Worker</code> constructor</a> for the detailed behavior of worker
1259threads with this property.</p>
1260</section><section><h3><code>process.execPath</code><span><a class="mark" href="#process_process_execpath" id="process_process_execpath">#</a></span></h3>
1261<div class="api_metadata">
1262<span>Added in: v0.1.100</span>
1263</div>
1264<ul>
1265<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1266</ul>
1267<p>The <code>process.execPath</code> property returns the absolute pathname of the executable
1268that started the Node.js process. Symbolic links, if any, are resolved.</p>
1269<!-- eslint-disable semi -->
1270<pre><code class="language-js"><span class="hljs-string">'/usr/local/bin/node'</span></code></pre>
1271</section><section><h3><code>process.exit([code])</code><span><a class="mark" href="#process_process_exit_code" id="process_process_exit_code">#</a></span></h3>
1272<div class="api_metadata">
1273<span>Added in: v0.1.13</span>
1274</div>
1275<ul>
1276<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> The exit code. <strong>Default:</strong> <code>0</code>.</li>
1277</ul>
1278<p>The <code>process.exit()</code> method instructs Node.js to terminate the process
1279synchronously with an exit status of <code>code</code>. If <code>code</code> is omitted, exit uses
1280either the 'success' code <code>0</code> or the value of <code>process.exitCode</code> if it has been
1281set. Node.js will not terminate until all the <a href="#process_event_exit"><code>'exit'</code></a> event listeners are
1282called.</p>
1283<p>To exit with a 'failure' code:</p>
1284<pre><code class="language-js">process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);</code></pre>
1285<p>The shell that executed Node.js should see the exit code as <code>1</code>.</p>
1286<p>Calling <code>process.exit()</code> will force the process to exit as quickly as possible
1287even if there are still asynchronous operations pending that have not yet
1288completed fully, including I/O operations to <code>process.stdout</code> and
1289<code>process.stderr</code>.</p>
1290<p>In most situations, it is not actually necessary to call <code>process.exit()</code>
1291explicitly. The Node.js process will exit on its own <em>if there is no additional
1292work pending</em> in the event loop. The <code>process.exitCode</code> property can be set to
1293tell the process which exit code to use when the process exits gracefully.</p>
1294<p>For instance, the following example illustrates a <em>misuse</em> of the
1295<code>process.exit()</code> method that could lead to data printed to stdout being
1296truncated and lost:</p>
1297<pre><code class="language-js"><span class="hljs-comment">// This is an example of what *not* to do:</span>
1298<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
1299  <span class="hljs-title function_">printUsageToStdout</span>();
1300  process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);
1301}</code></pre>
1302<p>The reason this is problematic is because writes to <code>process.stdout</code> in Node.js
1303are sometimes <em>asynchronous</em> and may occur over multiple ticks of the Node.js
1304event loop. Calling <code>process.exit()</code>, however, forces the process to exit
1305<em>before</em> those additional writes to <code>stdout</code> can be performed.</p>
1306<p>Rather than calling <code>process.exit()</code> directly, the code <em>should</em> set the
1307<code>process.exitCode</code> and allow the process to exit naturally by avoiding
1308scheduling any additional work for the event loop:</p>
1309<pre><code class="language-js"><span class="hljs-comment">// How to properly set the exit code while letting</span>
1310<span class="hljs-comment">// the process exit gracefully.</span>
1311<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
1312  <span class="hljs-title function_">printUsageToStdout</span>();
1313  process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
1314}</code></pre>
1315<p>If it is necessary to terminate the Node.js process due to an error condition,
1316throwing an <em>uncaught</em> error and allowing the process to terminate accordingly
1317is safer than calling <code>process.exit()</code>.</p>
1318<p>In <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads, this function stops the current thread rather
1319than the current process.</p>
1320</section><section><h3><code>process.exitCode</code><span><a class="mark" href="#process_process_exitcode" id="process_process_exitcode">#</a></span></h3>
1321<div class="api_metadata">
1322<span>Added in: v0.11.8</span>
1323</div>
1324<ul>
1325<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1326</ul>
1327<p>A number which will be the process exit code, when the process either
1328exits gracefully, or is exited via <a href="#process_process_exit_code"><code>process.exit()</code></a> without specifying
1329a code.</p>
1330<p>Specifying a code to <a href="#process_process_exit_code"><code>process.exit(code)</code></a> will override any
1331previous setting of <code>process.exitCode</code>.</p>
1332</section><section><h3><code>process.getegid()</code><span><a class="mark" href="#process_process_getegid" id="process_process_getegid">#</a></span></h3>
1333<div class="api_metadata">
1334<span>Added in: v2.0.0</span>
1335</div>
1336<p>The <code>process.getegid()</code> method returns the numerical effective group identity
1337of the Node.js process. (See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html"><code>getegid(2)</code></a>.)</p>
1338<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) {
1339  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
1340}</code></pre>
1341<p>This function is only available on POSIX platforms (i.e. not Windows or
1342Android).</p>
1343</section><section><h3><code>process.geteuid()</code><span><a class="mark" href="#process_process_geteuid" id="process_process_geteuid">#</a></span></h3>
1344<div class="api_metadata">
1345<span>Added in: v2.0.0</span>
1346</div>
1347<ul>
1348<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1349</ul>
1350<p>The <code>process.geteuid()</code> method returns the numerical effective user identity of
1351the process. (See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html"><code>geteuid(2)</code></a>.)</p>
1352<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) {
1353  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
1354}</code></pre>
1355<p>This function is only available on POSIX platforms (i.e. not Windows or
1356Android).</p>
1357</section><section><h3><code>process.getgid()</code><span><a class="mark" href="#process_process_getgid" id="process_process_getgid">#</a></span></h3>
1358<div class="api_metadata">
1359<span>Added in: v0.1.31</span>
1360</div>
1361<ul>
1362<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1363</ul>
1364<p>The <code>process.getgid()</code> method returns the numerical group identity of the
1365process. (See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html"><code>getgid(2)</code></a>.)</p>
1366<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) {
1367  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
1368}</code></pre>
1369<p>This function is only available on POSIX platforms (i.e. not Windows or
1370Android).</p>
1371</section><section><h3><code>process.getgroups()</code><span><a class="mark" href="#process_process_getgroups" id="process_process_getgroups">#</a></span></h3>
1372<div class="api_metadata">
1373<span>Added in: v0.9.4</span>
1374</div>
1375<ul>
1376<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
1377</ul>
1378<p>The <code>process.getgroups()</code> method returns an array with the supplementary group
1379IDs. POSIX leaves it unspecified if the effective group ID is included but
1380Node.js ensures it always is.</p>
1381<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) {
1382  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 16, 21, 297 ]</span>
1383}</code></pre>
1384<p>This function is only available on POSIX platforms (i.e. not Windows or
1385Android).</p>
1386</section><section><h3><code>process.getuid()</code><span><a class="mark" href="#process_process_getuid" id="process_process_getuid">#</a></span></h3>
1387<div class="api_metadata">
1388<span>Added in: v0.1.28</span>
1389</div>
1390<ul>
1391<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1392</ul>
1393<p>The <code>process.getuid()</code> method returns the numeric user identity of the process.
1394(See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html"><code>getuid(2)</code></a>.)</p>
1395<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) {
1396  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
1397}</code></pre>
1398<p>This function is only available on POSIX platforms (i.e. not Windows or
1399Android).</p>
1400</section><section><h3><code>process.hasUncaughtExceptionCaptureCallback()</code><span><a class="mark" href="#process_process_hasuncaughtexceptioncapturecallback" id="process_process_hasuncaughtexceptioncapturecallback">#</a></span></h3>
1401<div class="api_metadata">
1402<span>Added in: v9.3.0</span>
1403</div>
1404<ul>
1405<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1406</ul>
1407<p>Indicates whether a callback has been set using
1408<a href="#process_process_setuncaughtexceptioncapturecallback_fn"><code>process.setUncaughtExceptionCaptureCallback()</code></a>.</p>
1409</section><section><h3><code>process.hrtime([time])</code><span><a class="mark" href="#process_process_hrtime_time" id="process_process_hrtime_time">#</a></span></h3>
1410<div class="api_metadata">
1411<span>Added in: v0.7.6</span>
1412</div>
1413<p></p><div class="api_stability api_stability_3"><a href="documentation.html#documentation_stability_index">Stability: 3</a> - Legacy. Use <a href="#process_process_hrtime_bigint"><code>process.hrtime.bigint()</code></a> instead.</div><p></p>
1414<ul>
1415<li><code>time</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a> The result of a previous call to <code>process.hrtime()</code></li>
1416<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
1417</ul>
1418<p>This is the legacy version of <a href="#process_process_hrtime_bigint"><code>process.hrtime.bigint()</code></a>
1419before <code>bigint</code> was introduced in JavaScript.</p>
1420<p>The <code>process.hrtime()</code> method returns the current high-resolution real time
1421in a <code>[seconds, nanoseconds]</code> tuple <code>Array</code>, where <code>nanoseconds</code> is the
1422remaining part of the real time that can't be represented in second precision.</p>
1423<p><code>time</code> is an optional parameter that must be the result of a previous
1424<code>process.hrtime()</code> call to diff with the current time. If the parameter
1425passed in is not a tuple <code>Array</code>, a <code>TypeError</code> will be thrown. Passing in a
1426user-defined array instead of the result of a previous call to
1427<code>process.hrtime()</code> will lead to undefined behavior.</p>
1428<p>These times are relative to an arbitrary time in the
1429past, and not related to the time of day and therefore not subject to clock
1430drift. The primary use is for measuring performance between intervals:</p>
1431<pre><code class="language-js"><span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>;
1432<span class="hljs-keyword">const</span> time = process.<span class="hljs-title function_">hrtime</span>();
1433<span class="hljs-comment">// [ 1800216, 25 ]</span>
1434
1435<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
1436  <span class="hljs-keyword">const</span> diff = process.<span class="hljs-title function_">hrtime</span>(time);
1437  <span class="hljs-comment">// [ 1, 552 ]</span>
1438
1439  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Benchmark took <span class="hljs-subst">${diff[<span class="hljs-number">0</span>] * NS_PER_SEC + diff[<span class="hljs-number">1</span>]}</span> nanoseconds`</span>);
1440  <span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span>
1441}, <span class="hljs-number">1000</span>);</code></pre>
1442</section><section><h3><code>process.hrtime.bigint()</code><span><a class="mark" href="#process_process_hrtime_bigint" id="process_process_hrtime_bigint">#</a></span></h3>
1443<div class="api_metadata">
1444<span>Added in: v10.7.0</span>
1445</div>
1446<ul>
1447<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
1448</ul>
1449<p>The <code>bigint</code> version of the <a href="#process_process_hrtime_time"><code>process.hrtime()</code></a> method returning the
1450current high-resolution real time in nanoseconds as a <code>bigint</code>.</p>
1451<p>Unlike <a href="#process_process_hrtime_time"><code>process.hrtime()</code></a>, it does not support an additional <code>time</code>
1452argument since the difference can just be computed directly
1453by subtraction of the two <code>bigint</code>s.</p>
1454<pre><code class="language-js"><span class="hljs-keyword">const</span> start = process.<span class="hljs-property">hrtime</span>.<span class="hljs-title function_">bigint</span>();
1455<span class="hljs-comment">// 191051479007711n</span>
1456
1457<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
1458  <span class="hljs-keyword">const</span> end = process.<span class="hljs-property">hrtime</span>.<span class="hljs-title function_">bigint</span>();
1459  <span class="hljs-comment">// 191052633396993n</span>
1460
1461  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Benchmark took <span class="hljs-subst">${end - start}</span> nanoseconds`</span>);
1462  <span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span>
1463}, <span class="hljs-number">1000</span>);</code></pre>
1464</section><section><h3><code>process.initgroups(user, extraGroup)</code><span><a class="mark" href="#process_process_initgroups_user_extragroup" id="process_process_initgroups_user_extragroup">#</a></span></h3>
1465<div class="api_metadata">
1466<span>Added in: v0.9.4</span>
1467</div>
1468<ul>
1469<li><code>user</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The user name or numeric identifier.</li>
1470<li><code>extraGroup</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> A group name or numeric identifier.</li>
1471</ul>
1472<p>The <code>process.initgroups()</code> method reads the <code>/etc/group</code> file and initializes
1473the group access list, using all groups of which the user is a member. This is
1474a privileged operation that requires that the Node.js process either have <code>root</code>
1475access or the <code>CAP_SETGID</code> capability.</p>
1476<p>Use care when dropping privileges:</p>
1477<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 0 ]</span>
1478process.<span class="hljs-title function_">initgroups</span>(<span class="hljs-string">'nodeuser'</span>, <span class="hljs-number">1000</span>);     <span class="hljs-comment">// switch user</span>
1479<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 27, 30, 46, 1000, 0 ]</span>
1480process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>);                     <span class="hljs-comment">// drop root gid</span>
1481<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 27, 30, 46, 1000 ]</span></code></pre>
1482<p>This function is only available on POSIX platforms (i.e. not Windows or
1483Android).
1484This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
1485</section><section><h3><code>process.kill(pid[, signal])</code><span><a class="mark" href="#process_process_kill_pid_signal" id="process_process_kill_pid_signal">#</a></span></h3>
1486<div class="api_metadata">
1487<span>Added in: v0.0.6</span>
1488</div>
1489<ul>
1490<li><code>pid</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> A process ID</li>
1491<li><code>signal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The signal to send, either as a string or number.
1492<strong>Default:</strong> <code>'SIGTERM'</code>.</li>
1493</ul>
1494<p>The <code>process.kill()</code> method sends the <code>signal</code> to the process identified by
1495<code>pid</code>.</p>
1496<p>Signal names are strings such as <code>'SIGINT'</code> or <code>'SIGHUP'</code>. See <a href="#process_signal_events">Signal Events</a>
1497and <a href="http://man7.org/linux/man-pages/man2/kill.2.html"><code>kill(2)</code></a> for more information.</p>
1498<p>This method will throw an error if the target <code>pid</code> does not exist. As a special
1499case, a signal of <code>0</code> can be used to test for the existence of a process.
1500Windows platforms will throw an error if the <code>pid</code> is used to kill a process
1501group.</p>
1502<p>Even though the name of this function is <code>process.kill()</code>, it is really just a
1503signal sender, like the <code>kill</code> system call. The signal sent may do something
1504other than kill the target process.</p>
1505<pre><code class="language-js">process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> {
1506  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>);
1507});
1508
1509<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
1510  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>);
1511  process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
1512}, <span class="hljs-number">100</span>);
1513
1514process.<span class="hljs-title function_">kill</span>(process.<span class="hljs-property">pid</span>, <span class="hljs-string">'SIGHUP'</span>);</code></pre>
1515<p>When <code>SIGUSR1</code> is received by a Node.js process, Node.js will start the
1516debugger. See <a href="#process_signal_events">Signal Events</a>.</p>
1517</section><section><h3><code>process.mainModule</code><span><a class="mark" href="#process_process_mainmodule" id="process_process_mainmodule">#</a></span></h3>
1518<div class="api_metadata">
1519<span>Added in: v0.1.17</span><span>Deprecated since: v14.0.0</span>
1520</div>
1521<p></p><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated: Use <a href="modules.html#modules_accessing_the_main_module"><code>require.main</code></a> instead.</div><p></p>
1522<ul>
1523<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1524</ul>
1525<p>The <code>process.mainModule</code> property provides an alternative way of retrieving
1526<a href="modules.html#modules_accessing_the_main_module"><code>require.main</code></a>. The difference is that if the main module changes at
1527runtime, <a href="modules.html#modules_accessing_the_main_module"><code>require.main</code></a> may still refer to the original main module in
1528modules that were required before the change occurred. Generally, it's
1529safe to assume that the two refer to the same module.</p>
1530<p>As with <a href="modules.html#modules_accessing_the_main_module"><code>require.main</code></a>, <code>process.mainModule</code> will be <code>undefined</code> if there
1531is no entry script.</p>
1532</section><section><h3><code>process.memoryUsage()</code><span><a class="mark" href="#process_process_memoryusage" id="process_process_memoryusage">#</a></span></h3>
1533<div class="api_metadata">
1534<details class="changelog"><summary>History</summary>
1535<table>
1536<tbody><tr><th>Version</th><th>Changes</th></tr>
1537<tr><td>v13.9.0</td>
1538<td><p>Added <code>arrayBuffers</code> to the returned object.</p></td></tr>
1539<tr><td>v7.2.0</td>
1540<td><p>Added <code>external</code> to the returned object.</p></td></tr>
1541<tr><td>v0.1.16</td>
1542<td><p><span>Added in: v0.1.16</span></p></td></tr>
1543</tbody></table>
1544</details>
1545</div>
1546<ul>
1547<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1548<ul>
1549<li><code>rss</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1550<li><code>heapTotal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1551<li><code>heapUsed</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1552<li><code>external</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1553<li><code>arrayBuffers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1554</ul>
1555</li>
1556</ul>
1557<p>Returns an object describing the memory usage of the Node.js process measured in
1558bytes.</p>
1559<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">memoryUsage</span>());
1560<span class="hljs-comment">// Prints:</span>
1561<span class="hljs-comment">// {</span>
1562<span class="hljs-comment">//  rss: 4935680,</span>
1563<span class="hljs-comment">//  heapTotal: 1826816,</span>
1564<span class="hljs-comment">//  heapUsed: 650472,</span>
1565<span class="hljs-comment">//  external: 49879,</span>
1566<span class="hljs-comment">//  arrayBuffers: 9386</span>
1567<span class="hljs-comment">// }</span></code></pre>
1568<ul>
1569<li><code>heapTotal</code> and <code>heapUsed</code> refer to V8's memory usage.</li>
1570<li><code>external</code> refers to the memory usage of C++ objects bound to JavaScript
1571objects managed by V8.</li>
1572<li><code>rss</code>, Resident Set Size, is the amount of space occupied in the main
1573memory device (that is a subset of the total allocated memory) for the
1574process, including all C++ and JavaScript objects and code.</li>
1575<li><code>arrayBuffers</code> refers to memory allocated for <code>ArrayBuffer</code>s and
1576<code>SharedArrayBuffer</code>s, including all Node.js <a href="buffer.html"><code>Buffer</code></a>s.
1577This is also included in the <code>external</code> value. When Node.js is used as an
1578embedded library, this value may be <code>0</code> because allocations for <code>ArrayBuffer</code>s
1579may not be tracked in that case.</li>
1580</ul>
1581<p>When using <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads, <code>rss</code> will be a value that is valid for the
1582entire process, while the other fields will only refer to the current thread.</p>
1583<p>The <code>process.memoryUsage()</code> method iterates over each page to gather
1584information about memory usage which might be slow depending on the
1585program memory allocations.</p>
1586</section><section><h3><code>process.memoryUsage.rss()</code><span><a class="mark" href="#process_process_memoryusage_rss" id="process_process_memoryusage_rss">#</a></span></h3>
1587<div class="api_metadata">
1588<span>Added in: v14.18.0</span>
1589</div>
1590<ul>
1591<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1592</ul>
1593<p>The <code>process.memoryUsage.rss()</code> method returns an integer representing the
1594Resident Set Size (RSS) in bytes.</p>
1595<p>The Resident Set Size, is the amount of space occupied in the main
1596memory device (that is a subset of the total allocated memory) for the
1597process, including all C++ and JavaScript objects and code.</p>
1598<p>This is the same value as the <code>rss</code> property provided by <code>process.memoryUsage()</code>
1599but <code>process.memoryUsage.rss()</code> is faster.</p>
1600<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-property">memoryUsage</span>.<span class="hljs-title function_">rss</span>());
1601<span class="hljs-comment">// 35655680</span></code></pre>
1602</section><section><h3><code>process.nextTick(callback[, ...args])</code><span><a class="mark" href="#process_process_nexttick_callback_args" id="process_process_nexttick_callback_args">#</a></span></h3>
1603<div class="api_metadata">
1604<details class="changelog"><summary>History</summary>
1605<table>
1606<tbody><tr><th>Version</th><th>Changes</th></tr>
1607<tr><td>v1.8.1</td>
1608<td><p>Additional arguments after <code>callback</code> are now supported.</p></td></tr>
1609<tr><td>v0.1.26</td>
1610<td><p><span>Added in: v0.1.26</span></p></td></tr>
1611</tbody></table>
1612</details>
1613</div>
1614<ul>
1615<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1616<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Additional arguments to pass when invoking the <code>callback</code></li>
1617</ul>
1618<p><code>process.nextTick()</code> adds <code>callback</code> to the "next tick queue". This queue is
1619fully drained after the current operation on the JavaScript stack runs to
1620completion and before the event loop is allowed to continue. It's possible to
1621create an infinite loop if one were to recursively call <code>process.nextTick()</code>.
1622See the <a href="https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick">Event Loop</a> guide for more background.</p>
1623<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
1624process.<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
1625  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick callback'</span>);
1626});
1627<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
1628<span class="hljs-comment">// Output:</span>
1629<span class="hljs-comment">// start</span>
1630<span class="hljs-comment">// scheduled</span>
1631<span class="hljs-comment">// nextTick callback</span></code></pre>
1632<p>This is important when developing APIs in order to give users the opportunity
1633to assign event handlers <em>after</em> an object has been constructed but before any
1634I/O has occurred:</p>
1635<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) {
1636  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options);
1637
1638  process.<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
1639    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>();
1640  });
1641}
1642
1643<span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>();
1644thing.<span class="hljs-title function_">getReadyForStuff</span>();
1645
1646<span class="hljs-comment">// thing.startDoingStuff() gets called now, not before.</span></code></pre>
1647<p>It is very important for APIs to be either 100% synchronous or 100%
1648asynchronous. Consider this example:</p>
1649<pre><code class="language-js"><span class="hljs-comment">// WARNING!  DO NOT USE!  BAD UNSAFE HAZARD!</span>
1650<span class="hljs-keyword">function</span> <span class="hljs-title function_">maybeSync</span>(<span class="hljs-params">arg, cb</span>) {
1651  <span class="hljs-keyword">if</span> (arg) {
1652    <span class="hljs-title function_">cb</span>();
1653    <span class="hljs-keyword">return</span>;
1654  }
1655
1656  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
1657}</code></pre>
1658<p>This API is hazardous because in the following case:</p>
1659<pre><code class="language-js"><span class="hljs-keyword">const</span> maybeTrue = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">random</span>() > <span class="hljs-number">0.5</span>;
1660
1661<span class="hljs-title function_">maybeSync</span>(maybeTrue, <span class="hljs-function">() =></span> {
1662  <span class="hljs-title function_">foo</span>();
1663});
1664
1665<span class="hljs-title function_">bar</span>();</code></pre>
1666<p>It is not clear whether <code>foo()</code> or <code>bar()</code> will be called first.</p>
1667<p>The following approach is much better:</p>
1668<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) {
1669  <span class="hljs-keyword">if</span> (arg) {
1670    process.<span class="hljs-title function_">nextTick</span>(cb);
1671    <span class="hljs-keyword">return</span>;
1672  }
1673
1674  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
1675}</code></pre>
1676<h4>When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code><span><a class="mark" href="#process_when_to_use_queuemicrotask_vs_process_nexttick" id="process_when_to_use_queuemicrotask_vs_process_nexttick">#</a></span></h4>
1677<p>The <a href="globals.html#globals_queuemicrotask_callback"><code>queueMicrotask()</code></a> API is an alternative to <code>process.nextTick()</code> that
1678also defers execution of a function using the same microtask queue used to
1679execute the then, catch, and finally handlers of resolved promises. Within
1680Node.js, every time the "next tick queue" is drained, the microtask queue
1681is drained immediately after.</p>
1682<pre><code class="language-js"><span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">resolve</span>().<span class="hljs-title function_">then</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-number">2</span>));
1683<span class="hljs-title function_">queueMicrotask</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-number">3</span>));
1684process.<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-number">1</span>));
1685<span class="hljs-comment">// Output:</span>
1686<span class="hljs-comment">// 1</span>
1687<span class="hljs-comment">// 2</span>
1688<span class="hljs-comment">// 3</span></code></pre>
1689<p>For <em>most</em> userland use cases, the <code>queueMicrotask()</code> API provides a portable
1690and reliable mechanism for deferring execution that works across multiple
1691JavaScript platform environments and should be favored over <code>process.nextTick()</code>.
1692In simple scenarios, <code>queueMicrotask()</code> can be a drop-in replacement for
1693<code>process.nextTick()</code>.</p>
1694<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
1695<span class="hljs-title function_">queueMicrotask</span>(<span class="hljs-function">() =></span> {
1696  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask callback'</span>);
1697});
1698<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
1699<span class="hljs-comment">// Output:</span>
1700<span class="hljs-comment">// start</span>
1701<span class="hljs-comment">// scheduled</span>
1702<span class="hljs-comment">// microtask callback</span></code></pre>
1703<p>One note-worthy difference between the two APIs is that <code>process.nextTick()</code>
1704allows specifying additional values that will be passed as arguments to the
1705deferred function when it is called. Achieving the same result with
1706<code>queueMicrotask()</code> requires using either a closure or a bound function:</p>
1707<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">deferred</span>(<span class="hljs-params">a, b</span>) {
1708  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask'</span>, a + b);
1709}
1710
1711<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
1712<span class="hljs-title function_">queueMicrotask</span>(deferred.<span class="hljs-title function_">bind</span>(<span class="hljs-literal">undefined</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>));
1713<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
1714<span class="hljs-comment">// Output:</span>
1715<span class="hljs-comment">// start</span>
1716<span class="hljs-comment">// scheduled</span>
1717<span class="hljs-comment">// microtask 3</span></code></pre>
1718<p>There are minor differences in the way errors raised from within the next tick
1719queue and microtask queue are handled. Errors thrown within a queued microtask
1720callback should be handled within the queued callback when possible. If they are
1721not, the <code>process.on('uncaughtException')</code> event handler can be used to capture
1722and handle the errors.</p>
1723<p>When in doubt, unless the specific capabilities of <code>process.nextTick()</code> are
1724needed, use <code>queueMicrotask()</code>.</p>
1725</section><section><h3><code>process.noDeprecation</code><span><a class="mark" href="#process_process_nodeprecation" id="process_process_nodeprecation">#</a></span></h3>
1726<div class="api_metadata">
1727<span>Added in: v0.8.0</span>
1728</div>
1729<ul>
1730<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1731</ul>
1732<p>The <code>process.noDeprecation</code> property indicates whether the <code>--no-deprecation</code>
1733flag is set on the current Node.js process. See the documentation for
1734the <a href="#process_event_warning"><code>'warning'</code> event</a> and the
1735<a href="#process_process_emitwarning_warning_type_code_ctor"><code>emitWarning()</code> method</a> for more information about this
1736flag's behavior.</p>
1737</section><section><h3><code>process.pid</code><span><a class="mark" href="#process_process_pid" id="process_process_pid">#</a></span></h3>
1738<div class="api_metadata">
1739<span>Added in: v0.1.15</span>
1740</div>
1741<ul>
1742<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1743</ul>
1744<p>The <code>process.pid</code> property returns the PID of the process.</p>
1745<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This process is pid <span class="hljs-subst">${process.pid}</span>`</span>);</code></pre>
1746</section><section><h3><code>process.platform</code><span><a class="mark" href="#process_process_platform" id="process_process_platform">#</a></span></h3>
1747<div class="api_metadata">
1748<span>Added in: v0.1.16</span>
1749</div>
1750<ul>
1751<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1752</ul>
1753<p>The <code>process.platform</code> property returns a string identifying the operating
1754system platform on which the Node.js process is running.</p>
1755<p>Currently possible values are:</p>
1756<ul>
1757<li><code>'aix'</code></li>
1758<li><code>'darwin'</code></li>
1759<li><code>'freebsd'</code></li>
1760<li><code>'linux'</code></li>
1761<li><code>'openbsd'</code></li>
1762<li><code>'sunos'</code></li>
1763<li><code>'win32'</code></li>
1764</ul>
1765<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This platform is <span class="hljs-subst">${process.platform}</span>`</span>);</code></pre>
1766<p>The value <code>'android'</code> may also be returned if the Node.js is built on the
1767Android operating system. However, Android support in Node.js
1768<a href="https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os">is experimental</a>.</p>
1769</section><section><h3><code>process.ppid</code><span><a class="mark" href="#process_process_ppid" id="process_process_ppid">#</a></span></h3>
1770<div class="api_metadata">
1771<span>Added in: v9.2.0, v8.10.0, v6.13.0</span>
1772</div>
1773<ul>
1774<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1775</ul>
1776<p>The <code>process.ppid</code> property returns the PID of the parent of the
1777current process.</p>
1778<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`The parent process is pid <span class="hljs-subst">${process.ppid}</span>`</span>);</code></pre>
1779</section><section><h3><code>process.release</code><span><a class="mark" href="#process_process_release" id="process_process_release">#</a></span></h3>
1780<div class="api_metadata">
1781<details class="changelog"><summary>History</summary>
1782<table>
1783<tbody><tr><th>Version</th><th>Changes</th></tr>
1784<tr><td>v4.2.0</td>
1785<td><p>The <code>lts</code> property is now supported.</p></td></tr>
1786<tr><td>v3.0.0</td>
1787<td><p><span>Added in: v3.0.0</span></p></td></tr>
1788</tbody></table>
1789</details>
1790</div>
1791<ul>
1792<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1793</ul>
1794<p>The <code>process.release</code> property returns an <code>Object</code> containing metadata related
1795to the current release, including URLs for the source tarball and headers-only
1796tarball.</p>
1797<p><code>process.release</code> contains the following properties:</p>
1798<ul>
1799<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A value that will always be <code>'node'</code>.</li>
1800<li><code>sourceUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> an absolute URL pointing to a <em><code>.tar.gz</code></em> file containing
1801the source code of the current release.</li>
1802<li><code>headersUrl</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> an absolute URL pointing to a <em><code>.tar.gz</code></em> file containing
1803only the source header files for the current release. This file is
1804significantly smaller than the full source file and can be used for compiling
1805Node.js native add-ons.</li>
1806<li><code>libUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> an absolute URL pointing to a <em><code>node.lib</code></em> file matching the
1807architecture and version of the current release. This file is used for
1808compiling Node.js native add-ons. <em>This property is only present on Windows
1809builds of Node.js and will be missing on all other platforms.</em></li>
1810<li><code>lts</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> a string label identifying the <a href="https://github.com/nodejs/Release">LTS</a> label for this release.
1811This property only exists for LTS releases and is <code>undefined</code> for all other
1812release types, including <em>Current</em> releases.
1813Valid values include the LTS Release code names (including those
1814that are no longer supported).
1815<ul>
1816<li><code>'Dubnium'</code> for the 10.x LTS line beginning with 10.13.0.</li>
1817<li><code>'Erbium'</code> for the 12.x LTS line beginning with 12.13.0.</li>
1818</ul>
1819For other LTS Release code names, see <a href="https://github.com/nodejs/node/blob/HEAD/doc/changelogs/CHANGELOG_ARCHIVE.md">Node.js Changelog Archive</a></li>
1820</ul>
1821<!-- eslint-skip -->
1822<pre><code class="language-js">{
1823  <span class="hljs-attr">name</span>: <span class="hljs-string">'node'</span>,
1824  <span class="hljs-attr">lts</span>: <span class="hljs-string">'Erbium'</span>,
1825  <span class="hljs-attr">sourceUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v12.18.1/node-v12.18.1.tar.gz'</span>,
1826  <span class="hljs-attr">headersUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v12.18.1/node-v12.18.1-headers.tar.gz'</span>,
1827  <span class="hljs-attr">libUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v12.18.1/win-x64/node.lib'</span>
1828}</code></pre>
1829<p>In custom builds from non-release versions of the source tree, only the
1830<code>name</code> property may be present. The additional properties should not be
1831relied upon to exist.</p>
1832</section><section><h3><code>process.report</code><span><a class="mark" href="#process_process_report" id="process_process_report">#</a></span></h3>
1833<div class="api_metadata">
1834<details class="changelog"><summary>History</summary>
1835<table>
1836<tbody><tr><th>Version</th><th>Changes</th></tr>
1837<tr><td>v13.12.0</td>
1838<td><p>This API is no longer experimental.</p></td></tr>
1839<tr><td>v11.8.0</td>
1840<td><p><span>Added in: v11.8.0</span></p></td></tr>
1841</tbody></table>
1842</details>
1843</div>
1844<ul>
1845<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1846</ul>
1847<p><code>process.report</code> is an object whose methods are used to generate diagnostic
1848reports for the current process. Additional documentation is available in the
1849<a href="report.html">report documentation</a>.</p>
1850<h4><code>process.report.compact</code><span><a class="mark" href="#process_process_report_compact" id="process_process_report_compact">#</a></span></h4>
1851<div class="api_metadata">
1852<span>Added in: v13.12.0</span>
1853</div>
1854<ul>
1855<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1856</ul>
1857<p>Write reports in a compact format, single-line JSON, more easily consumable
1858by log processing systems than the default multi-line format designed for
1859human consumption.</p>
1860<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Reports are compact? <span class="hljs-subst">${process.report.compact}</span>`</span>);</code></pre>
1861<h4><code>process.report.directory</code><span><a class="mark" href="#process_process_report_directory" id="process_process_report_directory">#</a></span></h4>
1862<div class="api_metadata">
1863<details class="changelog"><summary>History</summary>
1864<table>
1865<tbody><tr><th>Version</th><th>Changes</th></tr>
1866<tr><td>v13.12.0</td>
1867<td><p>This API is no longer experimental.</p></td></tr>
1868<tr><td>v11.12.0</td>
1869<td><p><span>Added in: v11.12.0</span></p></td></tr>
1870</tbody></table>
1871</details>
1872</div>
1873<ul>
1874<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1875</ul>
1876<p>Directory where the report is written. The default value is the empty string,
1877indicating that reports are written to the current working directory of the
1878Node.js process.</p>
1879<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report directory is <span class="hljs-subst">${process.report.directory}</span>`</span>);</code></pre>
1880<h4><code>process.report.filename</code><span><a class="mark" href="#process_process_report_filename" id="process_process_report_filename">#</a></span></h4>
1881<div class="api_metadata">
1882<details class="changelog"><summary>History</summary>
1883<table>
1884<tbody><tr><th>Version</th><th>Changes</th></tr>
1885<tr><td>v13.12.0</td>
1886<td><p>This API is no longer experimental.</p></td></tr>
1887<tr><td>v11.12.0</td>
1888<td><p><span>Added in: v11.12.0</span></p></td></tr>
1889</tbody></table>
1890</details>
1891</div>
1892<ul>
1893<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1894</ul>
1895<p>Filename where the report is written. If set to the empty string, the output
1896filename will be comprised of a timestamp, PID, and sequence number. The default
1897value is the empty string.</p>
1898<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report filename is <span class="hljs-subst">${process.report.filename}</span>`</span>);</code></pre>
1899<h4><code>process.report.getReport([err])</code><span><a class="mark" href="#process_process_report_getreport_err" id="process_process_report_getreport_err">#</a></span></h4>
1900<div class="api_metadata">
1901<details class="changelog"><summary>History</summary>
1902<table>
1903<tbody><tr><th>Version</th><th>Changes</th></tr>
1904<tr><td>v13.12.0</td>
1905<td><p>This API is no longer experimental.</p></td></tr>
1906<tr><td>v11.8.0</td>
1907<td><p><span>Added in: v11.8.0</span></p></td></tr>
1908</tbody></table>
1909</details>
1910</div>
1911<ul>
1912<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> A custom error used for reporting the JavaScript stack.</li>
1913<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1914</ul>
1915<p>Returns a JavaScript Object representation of a diagnostic report for the
1916running process. The report's JavaScript stack trace is taken from <code>err</code>, if
1917present.</p>
1918<pre><code class="language-js"><span class="hljs-keyword">const</span> data = process.<span class="hljs-property">report</span>.<span class="hljs-title function_">getReport</span>();
1919<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data.<span class="hljs-property">header</span>.<span class="hljs-property">nodejsVersion</span>);
1920
1921<span class="hljs-comment">// Similar to process.report.writeReport()</span>
1922<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
1923fs.<span class="hljs-title function_">writeFileSync</span>(<span class="hljs-string">'my-report.log'</span>, util.<span class="hljs-title function_">inspect</span>(data), <span class="hljs-string">'utf8'</span>);</code></pre>
1924<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
1925<h4><code>process.report.reportOnFatalError</code><span><a class="mark" href="#process_process_report_reportonfatalerror" id="process_process_report_reportonfatalerror">#</a></span></h4>
1926<div class="api_metadata">
1927<details class="changelog"><summary>History</summary>
1928<table>
1929<tbody><tr><th>Version</th><th>Changes</th></tr>
1930<tr><td>v14.17.0</td>
1931<td><p>This API is no longer experimental.</p></td></tr>
1932<tr><td>v11.12.0</td>
1933<td><p><span>Added in: v11.12.0</span></p></td></tr>
1934</tbody></table>
1935</details>
1936</div>
1937<ul>
1938<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1939</ul>
1940<p>If <code>true</code>, a diagnostic report is generated on fatal errors, such as out of
1941memory errors or failed C++ assertions.</p>
1942<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on fatal error: <span class="hljs-subst">${process.report.reportOnFatalError}</span>`</span>);</code></pre>
1943<h4><code>process.report.reportOnSignal</code><span><a class="mark" href="#process_process_report_reportonsignal" id="process_process_report_reportonsignal">#</a></span></h4>
1944<div class="api_metadata">
1945<details class="changelog"><summary>History</summary>
1946<table>
1947<tbody><tr><th>Version</th><th>Changes</th></tr>
1948<tr><td>v13.12.0</td>
1949<td><p>This API is no longer experimental.</p></td></tr>
1950<tr><td>v11.12.0</td>
1951<td><p><span>Added in: v11.12.0</span></p></td></tr>
1952</tbody></table>
1953</details>
1954</div>
1955<ul>
1956<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1957</ul>
1958<p>If <code>true</code>, a diagnostic report is generated when the process receives the
1959signal specified by <code>process.report.signal</code>.</p>
1960<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on signal: <span class="hljs-subst">${process.report.reportOnSignal}</span>`</span>);</code></pre>
1961<h4><code>process.report.reportOnUncaughtException</code><span><a class="mark" href="#process_process_report_reportonuncaughtexception" id="process_process_report_reportonuncaughtexception">#</a></span></h4>
1962<div class="api_metadata">
1963<details class="changelog"><summary>History</summary>
1964<table>
1965<tbody><tr><th>Version</th><th>Changes</th></tr>
1966<tr><td>v13.12.0</td>
1967<td><p>This API is no longer experimental.</p></td></tr>
1968<tr><td>v11.12.0</td>
1969<td><p><span>Added in: v11.12.0</span></p></td></tr>
1970</tbody></table>
1971</details>
1972</div>
1973<ul>
1974<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1975</ul>
1976<p>If <code>true</code>, a diagnostic report is generated on uncaught exception.</p>
1977<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on exception: <span class="hljs-subst">${process.report.reportOnUncaughtException}</span>`</span>);</code></pre>
1978<h4><code>process.report.signal</code><span><a class="mark" href="#process_process_report_signal" id="process_process_report_signal">#</a></span></h4>
1979<div class="api_metadata">
1980<details class="changelog"><summary>History</summary>
1981<table>
1982<tbody><tr><th>Version</th><th>Changes</th></tr>
1983<tr><td>v13.12.0</td>
1984<td><p>This API is no longer experimental.</p></td></tr>
1985<tr><td>v11.12.0</td>
1986<td><p><span>Added in: v11.12.0</span></p></td></tr>
1987</tbody></table>
1988</details>
1989</div>
1990<ul>
1991<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1992</ul>
1993<p>The signal used to trigger the creation of a diagnostic report. Defaults to
1994<code>'SIGUSR2'</code>.</p>
1995<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report signal: <span class="hljs-subst">${process.report.signal}</span>`</span>);</code></pre>
1996<h4><code>process.report.writeReport([filename][, err])</code><span><a class="mark" href="#process_process_report_writereport_filename_err" id="process_process_report_writereport_filename_err">#</a></span></h4>
1997<div class="api_metadata">
1998<details class="changelog"><summary>History</summary>
1999<table>
2000<tbody><tr><th>Version</th><th>Changes</th></tr>
2001<tr><td>v13.12.0</td>
2002<td><p>This API is no longer experimental.</p></td></tr>
2003<tr><td>v11.8.0</td>
2004<td><p><span>Added in: v11.8.0</span></p></td></tr>
2005</tbody></table>
2006</details>
2007</div>
2008<ul>
2009<li>
2010<p><code>filename</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Name of the file where the report is written. This
2011should be a relative path, that will be appended to the directory specified in
2012<code>process.report.directory</code>, or the current working directory of the Node.js
2013process, if unspecified.</p>
2014</li>
2015<li>
2016<p><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type">&#x3C;Error></a> A custom error used for reporting the JavaScript stack.</p>
2017</li>
2018<li>
2019<p>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Returns the filename of the generated report.</p>
2020</li>
2021</ul>
2022<p>Writes a diagnostic report to a file. If <code>filename</code> is not provided, the default
2023filename includes the date, time, PID, and a sequence number. The report's
2024JavaScript stack trace is taken from <code>err</code>, if present.</p>
2025<pre><code class="language-js">process.<span class="hljs-property">report</span>.<span class="hljs-title function_">writeReport</span>();</code></pre>
2026<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
2027</section><section><h3><code>process.resourceUsage()</code><span><a class="mark" href="#process_process_resourceusage" id="process_process_resourceusage">#</a></span></h3>
2028<div class="api_metadata">
2029<span>Added in: v12.6.0</span>
2030</div>
2031<ul>
2032<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> the resource usage for the current process. All of these
2033values come from the <code>uv_getrusage</code> call which returns
2034a <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t"><code>uv_rusage_t</code> struct</a>.
2035<ul>
2036<li><code>userCPUTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_utime</code> computed in microseconds.
2037It is the same value as <a href="#process_process_cpuusage_previousvalue"><code>process.cpuUsage().user</code></a>.</li>
2038<li><code>systemCPUTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_stime</code> computed in microseconds.
2039It is the same value as <a href="#process_process_cpuusage_previousvalue"><code>process.cpuUsage().system</code></a>.</li>
2040<li><code>maxRSS</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_maxrss</code> which is the maximum resident set
2041size used in kilobytes.</li>
2042<li><code>sharedMemorySize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_ixrss</code> but is not supported by
2043any platform.</li>
2044<li><code>unsharedDataSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_idrss</code> but is not supported by
2045any platform.</li>
2046<li><code>unsharedStackSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_isrss</code> but is not supported by
2047any platform.</li>
2048<li><code>minorPageFault</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_minflt</code> which is the number of
2049minor page faults for the process, see
2050<a href="https://en.wikipedia.org/wiki/Page_fault#Minor">this article for more details</a>.</li>
2051<li><code>majorPageFault</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_majflt</code> which is the number of
2052major page faults for the process, see
2053<a href="https://en.wikipedia.org/wiki/Page_fault#Major">this article for more details</a>. This field is not
2054supported on Windows.</li>
2055<li><code>swappedOut</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_nswap</code> but is not supported by any
2056platform.</li>
2057<li><code>fsRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_inblock</code> which is the number of times the
2058file system had to perform input.</li>
2059<li><code>fsWrite</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_oublock</code> which is the number of times the
2060file system had to perform output.</li>
2061<li><code>ipcSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_msgsnd</code> but is not supported by any
2062platform.</li>
2063<li><code>ipcReceived</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_msgrcv</code> but is not supported by any
2064platform.</li>
2065<li><code>signalsCount</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_nsignals</code> but is not supported by any
2066platform.</li>
2067<li><code>voluntaryContextSwitches</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_nvcsw</code> which is the
2068number of times a CPU context switch resulted due to a process voluntarily
2069giving up the processor before its time slice was completed (usually to
2070await availability of a resource). This field is not supported on Windows.</li>
2071<li><code>involuntaryContextSwitches</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> maps to <code>ru_nivcsw</code> which is the
2072number of times a CPU context switch resulted due to a higher priority
2073process becoming runnable or because the current process exceeded its
2074time slice. This field is not supported on Windows.</li>
2075</ul>
2076</li>
2077</ul>
2078<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">resourceUsage</span>());
2079<span class="hljs-comment">/*
2080  Will output:
2081  {
2082    userCPUTime: 82872,
2083    systemCPUTime: 4143,
2084    maxRSS: 33164,
2085    sharedMemorySize: 0,
2086    unsharedDataSize: 0,
2087    unsharedStackSize: 0,
2088    minorPageFault: 2469,
2089    majorPageFault: 0,
2090    swappedOut: 0,
2091    fsRead: 0,
2092    fsWrite: 8,
2093    ipcSent: 0,
2094    ipcReceived: 0,
2095    signalsCount: 0,
2096    voluntaryContextSwitches: 79,
2097    involuntaryContextSwitches: 1
2098  }
2099*/</span></code></pre>
2100</section><section><h3><code>process.send(message[, sendHandle[, options]][, callback])</code><span><a class="mark" href="#process_process_send_message_sendhandle_options_callback" id="process_process_send_message_sendhandle_options_callback">#</a></span></h3>
2101<div class="api_metadata">
2102<span>Added in: v0.5.9</span>
2103</div>
2104<ul>
2105<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2106<li><code>sendHandle</code> <a href="net.html#net_class_net_server" class="type">&#x3C;net.Server></a> | <a href="net.html#net_class_net_socket" class="type">&#x3C;net.Socket></a></li>
2107<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> used to parameterize the sending of certain types of
2108handles.<code>options</code> supports the following properties:
2109<ul>
2110<li><code>keepOpen</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> A value that can be used when passing instances of
2111<code>net.Socket</code>. When <code>true</code>, the socket is kept open in the sending process.
2112<strong>Default:</strong> <code>false</code>.</li>
2113</ul>
2114</li>
2115<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
2116<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2117</ul>
2118<p>If Node.js is spawned with an IPC channel, the <code>process.send()</code> method can be
2119used to send messages to the parent process. Messages will be received as a
2120<a href="child_process.html#child_process_event_message"><code>'message'</code></a> event on the parent's <a href="child_process.html#child_process_class_childprocess"><code>ChildProcess</code></a> object.</p>
2121<p>If Node.js was not spawned with an IPC channel, <code>process.send</code> will be
2122<code>undefined</code>.</p>
2123<p>The message goes through serialization and parsing. The resulting message might
2124not be the same as what is originally sent.</p>
2125</section><section><h3><code>process.setegid(id)</code><span><a class="mark" href="#process_process_setegid_id" id="process_process_setegid_id">#</a></span></h3>
2126<div class="api_metadata">
2127<span>Added in: v2.0.0</span>
2128</div>
2129<ul>
2130<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> A group name or ID</li>
2131</ul>
2132<p>The <code>process.setegid()</code> method sets the effective group identity of the process.
2133(See <a href="http://man7.org/linux/man-pages/man2/setegid.2.html"><code>setegid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a group
2134name string. If a group name is specified, this method blocks while resolving
2135the associated a numeric ID.</p>
2136<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> &#x26;&#x26; process.<span class="hljs-property">setegid</span>) {
2137  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
2138  <span class="hljs-keyword">try</span> {
2139    process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>);
2140    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
2141  } <span class="hljs-keyword">catch</span> (err) {
2142    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
2143  }
2144}</code></pre>
2145<p>This function is only available on POSIX platforms (i.e. not Windows or
2146Android).
2147This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
2148</section><section><h3><code>process.seteuid(id)</code><span><a class="mark" href="#process_process_seteuid_id" id="process_process_seteuid_id">#</a></span></h3>
2149<div class="api_metadata">
2150<span>Added in: v2.0.0</span>
2151</div>
2152<ul>
2153<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> A user name or ID</li>
2154</ul>
2155<p>The <code>process.seteuid()</code> method sets the effective user identity of the process.
2156(See <a href="http://man7.org/linux/man-pages/man2/seteuid.2.html"><code>seteuid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a username
2157string. If a username is specified, the method blocks while resolving the
2158associated numeric ID.</p>
2159<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> &#x26;&#x26; process.<span class="hljs-property">seteuid</span>) {
2160  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
2161  <span class="hljs-keyword">try</span> {
2162    process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>);
2163    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
2164  } <span class="hljs-keyword">catch</span> (err) {
2165    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
2166  }
2167}</code></pre>
2168<p>This function is only available on POSIX platforms (i.e. not Windows or
2169Android).
2170This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
2171</section><section><h3><code>process.setgid(id)</code><span><a class="mark" href="#process_process_setgid_id" id="process_process_setgid_id">#</a></span></h3>
2172<div class="api_metadata">
2173<span>Added in: v0.1.31</span>
2174</div>
2175<ul>
2176<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The group name or ID</li>
2177</ul>
2178<p>The <code>process.setgid()</code> method sets the group identity of the process. (See
2179<a href="http://man7.org/linux/man-pages/man2/setgid.2.html"><code>setgid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a group name
2180string. If a group name is specified, this method blocks while resolving the
2181associated numeric ID.</p>
2182<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> &#x26;&#x26; process.<span class="hljs-property">setgid</span>) {
2183  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
2184  <span class="hljs-keyword">try</span> {
2185    process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>);
2186    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
2187  } <span class="hljs-keyword">catch</span> (err) {
2188    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
2189  }
2190}</code></pre>
2191<p>This function is only available on POSIX platforms (i.e. not Windows or
2192Android).
2193This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
2194</section><section><h3><code>process.setgroups(groups)</code><span><a class="mark" href="#process_process_setgroups_groups" id="process_process_setgroups_groups">#</a></span></h3>
2195<div class="api_metadata">
2196<span>Added in: v0.9.4</span>
2197</div>
2198<ul>
2199<li><code>groups</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
2200</ul>
2201<p>The <code>process.setgroups()</code> method sets the supplementary group IDs for the
2202Node.js process. This is a privileged operation that requires the Node.js
2203process to have <code>root</code> or the <code>CAP_SETGID</code> capability.</p>
2204<p>The <code>groups</code> array can contain numeric group IDs, group names, or both.</p>
2205<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> &#x26;&#x26; process.<span class="hljs-property">setgroups</span>) {
2206  <span class="hljs-keyword">try</span> {
2207    process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]);
2208    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// new groups</span>
2209  } <span class="hljs-keyword">catch</span> (err) {
2210    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Failed to set groups: <span class="hljs-subst">${err}</span>`</span>);
2211  }
2212}</code></pre>
2213<p>This function is only available on POSIX platforms (i.e. not Windows or
2214Android).
2215This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
2216</section><section><h3><code>process.setuid(id)</code><span><a class="mark" href="#process_process_setuid_id" id="process_process_setuid_id">#</a></span></h3>
2217<div class="api_metadata">
2218<span>Added in: v0.1.28</span>
2219</div>
2220<ul>
2221<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
2222</ul>
2223<p>The <code>process.setuid(id)</code> method sets the user identity of the process. (See
2224<a href="http://man7.org/linux/man-pages/man2/setuid.2.html"><code>setuid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a username string.
2225If a username is specified, the method blocks while resolving the associated
2226numeric ID.</p>
2227<pre><code class="language-js"><span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> &#x26;&#x26; process.<span class="hljs-property">setuid</span>) {
2228  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
2229  <span class="hljs-keyword">try</span> {
2230    process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>);
2231    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
2232  } <span class="hljs-keyword">catch</span> (err) {
2233    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
2234  }
2235}</code></pre>
2236<p>This function is only available on POSIX platforms (i.e. not Windows or
2237Android).
2238This feature is not available in <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads.</p>
2239</section><section><h3><code>process.setSourceMapsEnabled(val)</code><span><a class="mark" href="#process_process_setsourcemapsenabled_val" id="process_process_setsourcemapsenabled_val">#</a></span></h3>
2240<div class="api_metadata">
2241<span>Added in: v14.18.0</span>
2242</div>
2243<p></p><div class="api_stability api_stability_1"><a href="documentation.html#documentation_stability_index">Stability: 1</a> - Experimental</div><p></p>
2244<ul>
2245<li><code>val</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2246</ul>
2247<p>This function enables or disables the <a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for
2248stack traces.</p>
2249<p>It provides same features as launching Node.js process with commandline options
2250<code>--enable-source-maps</code>.</p>
2251<p>Only source maps in JavaScript files that are loaded after source maps has been
2252enabled will be parsed and loaded.</p>
2253</section><section><h3><code>process.setUncaughtExceptionCaptureCallback(fn)</code><span><a class="mark" href="#process_process_setuncaughtexceptioncapturecallback_fn" id="process_process_setuncaughtexceptioncapturecallback_fn">#</a></span></h3>
2254<div class="api_metadata">
2255<span>Added in: v9.3.0</span>
2256</div>
2257<ul>
2258<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type">&#x3C;null></a></li>
2259</ul>
2260<p>The <code>process.setUncaughtExceptionCaptureCallback()</code> function sets a function
2261that will be invoked when an uncaught exception occurs, which will receive the
2262exception value itself as its first argument.</p>
2263<p>If such a function is set, the <a href="#process_event_uncaughtexception"><code>'uncaughtException'</code></a> event will
2264not be emitted. If <code>--abort-on-uncaught-exception</code> was passed from the
2265command line or set through <a href="v8.html#v8_v8_setflagsfromstring_flags"><code>v8.setFlagsFromString()</code></a>, the process will
2266not abort. Actions configured to take place on exceptions such as report
2267generations will be affected too</p>
2268<p>To unset the capture function,
2269<code>process.setUncaughtExceptionCaptureCallback(null)</code> may be used. Calling this
2270method with a non-<code>null</code> argument while another capture function is set will
2271throw an error.</p>
2272<p>Using this function is mutually exclusive with using the deprecated
2273<a href="domain.html"><code>domain</code></a> built-in module.</p>
2274</section><section><h3><code>process.stderr</code><span><a class="mark" href="#process_process_stderr" id="process_process_stderr">#</a></span></h3>
2275<ul>
2276<li><a href="stream.html#stream_stream" class="type">&#x3C;Stream></a></li>
2277</ul>
2278<p>The <code>process.stderr</code> property returns a stream connected to
2279<code>stderr</code> (fd <code>2</code>). It is a <a href="net.html#net_class_net_socket"><code>net.Socket</code></a> (which is a <a href="stream.html#stream_duplex_and_transform_streams">Duplex</a>
2280stream) unless fd <code>2</code> refers to a file, in which case it is
2281a <a href="stream.html#stream_writable_streams">Writable</a> stream.</p>
2282<p><code>process.stderr</code> differs from other Node.js streams in important ways. See
2283<a href="#process_a_note_on_process_i_o">note on process I/O</a> for more information.</p>
2284<h4><code>process.stderr.fd</code><span><a class="mark" href="#process_process_stderr_fd" id="process_process_stderr_fd">#</a></span></h4>
2285<ul>
2286<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
2287</ul>
2288<p>This property refers to the value of underlying file descriptor of
2289<code>process.stderr</code>. The value is fixed at <code>2</code>. In <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads,
2290this field does not exist.</p>
2291</section><section><h3><code>process.stdin</code><span><a class="mark" href="#process_process_stdin" id="process_process_stdin">#</a></span></h3>
2292<ul>
2293<li><a href="stream.html#stream_stream" class="type">&#x3C;Stream></a></li>
2294</ul>
2295<p>The <code>process.stdin</code> property returns a stream connected to
2296<code>stdin</code> (fd <code>0</code>). It is a <a href="net.html#net_class_net_socket"><code>net.Socket</code></a> (which is a <a href="stream.html#stream_duplex_and_transform_streams">Duplex</a>
2297stream) unless fd <code>0</code> refers to a file, in which case it is
2298a <a href="stream.html#stream_readable_streams">Readable</a> stream.</p>
2299<p>For details of how to read from <code>stdin</code> see <a href="stream.html#stream_readable_read_size"><code>readable.read()</code></a>.</p>
2300<p>As a <a href="stream.html#stream_duplex_and_transform_streams">Duplex</a> stream, <code>process.stdin</code> can also be used in "old" mode that
2301is compatible with scripts written for Node.js prior to v0.10.
2302For more information see <a href="stream.html#stream_compatibility_with_older_node_js_versions">Stream compatibility</a>.</p>
2303<p>In "old" streams mode the <code>stdin</code> stream is paused by default, so one
2304must call <code>process.stdin.resume()</code> to read from it. Note also that calling
2305<code>process.stdin.resume()</code> itself would switch stream to "old" mode.</p>
2306<h4><code>process.stdin.fd</code><span><a class="mark" href="#process_process_stdin_fd" id="process_process_stdin_fd">#</a></span></h4>
2307<ul>
2308<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
2309</ul>
2310<p>This property refers to the value of underlying file descriptor of
2311<code>process.stdin</code>. The value is fixed at <code>0</code>. In <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads,
2312this field does not exist.</p>
2313</section><section><h3><code>process.stdout</code><span><a class="mark" href="#process_process_stdout" id="process_process_stdout">#</a></span></h3>
2314<ul>
2315<li><a href="stream.html#stream_stream" class="type">&#x3C;Stream></a></li>
2316</ul>
2317<p>The <code>process.stdout</code> property returns a stream connected to
2318<code>stdout</code> (fd <code>1</code>). It is a <a href="net.html#net_class_net_socket"><code>net.Socket</code></a> (which is a <a href="stream.html#stream_duplex_and_transform_streams">Duplex</a>
2319stream) unless fd <code>1</code> refers to a file, in which case it is
2320a <a href="stream.html#stream_writable_streams">Writable</a> stream.</p>
2321<p>For example, to copy <code>process.stdin</code> to <code>process.stdout</code>:</p>
2322<pre><code class="language-js">process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">pipe</span>(process.<span class="hljs-property">stdout</span>);</code></pre>
2323<p><code>process.stdout</code> differs from other Node.js streams in important ways. See
2324<a href="#process_a_note_on_process_i_o">note on process I/O</a> for more information.</p>
2325<h4><code>process.stdout.fd</code><span><a class="mark" href="#process_process_stdout_fd" id="process_process_stdout_fd">#</a></span></h4>
2326<ul>
2327<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
2328</ul>
2329<p>This property refers to the value of underlying file descriptor of
2330<code>process.stdout</code>. The value is fixed at <code>1</code>. In <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads,
2331this field does not exist.</p>
2332<h4>A note on process I/O<span><a class="mark" href="#process_a_note_on_process_i_o" id="process_a_note_on_process_i_o">#</a></span></h4>
2333<p><code>process.stdout</code> and <code>process.stderr</code> differ from other Node.js streams in
2334important ways:</p>
2335<ol>
2336<li>They are used internally by <a href="console.html#console_console_log_data_args"><code>console.log()</code></a> and <a href="console.html#console_console_error_data_args"><code>console.error()</code></a>,
2337respectively.</li>
2338<li>Writes may be synchronous depending on what the stream is connected to
2339and whether the system is Windows or POSIX:
2340<ul>
2341<li>Files: <em>synchronous</em> on Windows and POSIX</li>
2342<li>TTYs (Terminals): <em>asynchronous</em> on Windows, <em>synchronous</em> on POSIX</li>
2343<li>Pipes (and sockets): <em>synchronous</em> on Windows, <em>asynchronous</em> on POSIX</li>
2344</ul>
2345</li>
2346</ol>
2347<p>These behaviors are partly for historical reasons, as changing them would
2348create backward incompatibility, but they are also expected by some users.</p>
2349<p>Synchronous writes avoid problems such as output written with <code>console.log()</code> or
2350<code>console.error()</code> being unexpectedly interleaved, or not written at all if
2351<code>process.exit()</code> is called before an asynchronous write completes. See
2352<a href="#process_process_exit_code"><code>process.exit()</code></a> for more information.</p>
2353<p><em><strong>Warning</strong></em>: Synchronous writes block the event loop until the write has
2354completed. This can be near instantaneous in the case of output to a file, but
2355under high system load, pipes that are not being read at the receiving end, or
2356with slow terminals or file systems, its possible for the event loop to be
2357blocked often enough and long enough to have severe negative performance
2358impacts. This may not be a problem when writing to an interactive terminal
2359session, but consider this particularly careful when doing production logging to
2360the process output streams.</p>
2361<p>To check if a stream is connected to a <a href="tty.html#tty_tty">TTY</a> context, check the <code>isTTY</code>
2362property.</p>
2363<p>For instance:</p>
2364<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdin.isTTY)"</span></span>
2365true
2366<span class="hljs-meta">$ </span><span class="language-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"foo"</span> | node -p <span class="hljs-string">"Boolean(process.stdin.isTTY)"</span></span>
2367false
2368<span class="hljs-meta">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span></span>
2369true
2370<span class="hljs-meta">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span> | cat</span>
2371false</code></pre>
2372<p>See the <a href="tty.html#tty_tty">TTY</a> documentation for more information.</p>
2373</section><section><h3><code>process.throwDeprecation</code><span><a class="mark" href="#process_process_throwdeprecation" id="process_process_throwdeprecation">#</a></span></h3>
2374<div class="api_metadata">
2375<span>Added in: v0.9.12</span>
2376</div>
2377<ul>
2378<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2379</ul>
2380<p>The initial value of <code>process.throwDeprecation</code> indicates whether the
2381<code>--throw-deprecation</code> flag is set on the current Node.js process.
2382<code>process.throwDeprecation</code> is mutable, so whether or not deprecation
2383warnings result in errors may be altered at runtime. See the
2384documentation for the <a href="#process_event_warning"><code>'warning'</code> event</a> and the
2385<a href="#process_process_emitwarning_warning_type_code_ctor"><code>emitWarning()</code> method</a> for more information.</p>
2386<pre><code class="language-console"><span class="hljs-meta">$ </span><span class="language-bash">node --throw-deprecation -p <span class="hljs-string">"process.throwDeprecation"</span></span>
2387true
2388<span class="hljs-meta">$ </span><span class="language-bash">node -p <span class="hljs-string">"process.throwDeprecation"</span></span>
2389undefined
2390<span class="hljs-meta">$ </span><span class="language-bash">node</span>
2391<span class="hljs-meta">> </span><span class="language-bash">process.emitWarning(<span class="hljs-string">'test'</span>, <span class="hljs-string">'DeprecationWarning'</span>);</span>
2392undefined
2393<span class="hljs-meta">> </span><span class="language-bash">(node:26598) DeprecationWarning: <span class="hljs-built_in">test</span></span>
2394<span class="hljs-meta">> </span><span class="language-bash">process.throwDeprecation = <span class="hljs-literal">true</span>;</span>
2395true
2396<span class="hljs-meta">> </span><span class="language-bash">process.emitWarning(<span class="hljs-string">'test'</span>, <span class="hljs-string">'DeprecationWarning'</span>);</span>
2397Thrown:
2398[DeprecationWarning: test] { name: 'DeprecationWarning' }</code></pre>
2399</section><section><h3><code>process.title</code><span><a class="mark" href="#process_process_title" id="process_process_title">#</a></span></h3>
2400<div class="api_metadata">
2401<span>Added in: v0.1.104</span>
2402</div>
2403<ul>
2404<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
2405</ul>
2406<p>The <code>process.title</code> property returns the current process title (i.e. returns
2407the current value of <code>ps</code>). Assigning a new value to <code>process.title</code> modifies
2408the current value of <code>ps</code>.</p>
2409<p>When a new value is assigned, different platforms will impose different maximum
2410length restrictions on the title. Usually such restrictions are quite limited.
2411For instance, on Linux and macOS, <code>process.title</code> is limited to the size of the
2412binary name plus the length of the command-line arguments because setting the
2413<code>process.title</code> overwrites the <code>argv</code> memory of the process. Node.js v0.8
2414allowed for longer process title strings by also overwriting the <code>environ</code>
2415memory but that was potentially insecure and confusing in some (rather obscure)
2416cases.</p>
2417<p>Assigning a value to <code>process.title</code> might not result in an accurate label
2418within process manager applications such as macOS Activity Monitor or Windows
2419Services Manager.</p>
2420</section><section><h3><code>process.traceDeprecation</code><span><a class="mark" href="#process_process_tracedeprecation" id="process_process_tracedeprecation">#</a></span></h3>
2421<div class="api_metadata">
2422<span>Added in: v0.8.0</span>
2423</div>
2424<ul>
2425<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2426</ul>
2427<p>The <code>process.traceDeprecation</code> property indicates whether the
2428<code>--trace-deprecation</code> flag is set on the current Node.js process. See the
2429documentation for the <a href="#process_event_warning"><code>'warning'</code> event</a> and the
2430<a href="#process_process_emitwarning_warning_type_code_ctor"><code>emitWarning()</code> method</a> for more information about this
2431flag's behavior.</p>
2432</section><section><h3><code>process.umask()</code><span><a class="mark" href="#process_process_umask" id="process_process_umask">#</a></span></h3>
2433<div class="api_metadata">
2434<details class="changelog"><summary>History</summary>
2435<table>
2436<tbody><tr><th>Version</th><th>Changes</th></tr>
2437<tr><td>v14.0.0, v12.19.0</td>
2438<td><p>Calling <code>process.umask()</code> with no arguments is deprecated.</p></td></tr>
2439<tr><td>v0.1.19</td>
2440<td><p><span>Added in: v0.1.19</span></p></td></tr>
2441</tbody></table>
2442</details>
2443</div>
2444<p></p><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated. Calling <code>process.umask()</code> with no argument causes
2445the process-wide umask to be written twice. This introduces a race condition
2446between threads, and is a potential security vulnerability. There is no safe,
2447cross-platform alternative API.</div><p></p>
2448<p><code>process.umask()</code> returns the Node.js process's file mode creation mask. Child
2449processes inherit the mask from the parent process.</p>
2450</section><section><h3><code>process.umask(mask)</code><span><a class="mark" href="#process_process_umask_mask" id="process_process_umask_mask">#</a></span></h3>
2451<div class="api_metadata">
2452<span>Added in: v0.1.19</span>
2453</div>
2454<ul>
2455<li><code>mask</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
2456</ul>
2457<p><code>process.umask(mask)</code> sets the Node.js process's file mode creation mask. Child
2458processes inherit the mask from the parent process. Returns the previous mask.</p>
2459<pre><code class="language-js"><span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>;
2460<span class="hljs-keyword">const</span> oldmask = process.<span class="hljs-title function_">umask</span>(newmask);
2461<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(
2462  <span class="hljs-string">`Changed umask from <span class="hljs-subst">${oldmask.toString(<span class="hljs-number">8</span>)}</span> to <span class="hljs-subst">${newmask.toString(<span class="hljs-number">8</span>)}</span>`</span>
2463);</code></pre>
2464<p>In <a href="worker_threads.html#worker_threads_class_worker"><code>Worker</code></a> threads, <code>process.umask(mask)</code> will throw an exception.</p>
2465</section><section><h3><code>process.uptime()</code><span><a class="mark" href="#process_process_uptime" id="process_process_uptime">#</a></span></h3>
2466<div class="api_metadata">
2467<span>Added in: v0.5.0</span>
2468</div>
2469<ul>
2470<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
2471</ul>
2472<p>The <code>process.uptime()</code> method returns the number of seconds the current Node.js
2473process has been running.</p>
2474<p>The return value includes fractions of a second. Use <code>Math.floor()</code> to get whole
2475seconds.</p>
2476</section><section><h3><code>process.version</code><span><a class="mark" href="#process_process_version" id="process_process_version">#</a></span></h3>
2477<div class="api_metadata">
2478<span>Added in: v0.1.3</span>
2479</div>
2480<ul>
2481<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
2482</ul>
2483<p>The <code>process.version</code> property contains the Node.js version string.</p>
2484<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Version: <span class="hljs-subst">${process.version}</span>`</span>);
2485<span class="hljs-comment">// Version: v14.8.0</span></code></pre>
2486<p>To get the version string without the prepended <em>v</em>, use
2487<code>process.versions.node</code>.</p>
2488</section><section><h3><code>process.versions</code><span><a class="mark" href="#process_process_versions" id="process_process_versions">#</a></span></h3>
2489<div class="api_metadata">
2490<details class="changelog"><summary>History</summary>
2491<table>
2492<tbody><tr><th>Version</th><th>Changes</th></tr>
2493<tr><td>v9.0.0</td>
2494<td><p>The <code>v8</code> property now includes a Node.js specific suffix.</p></td></tr>
2495<tr><td>v4.2.0</td>
2496<td><p>The <code>icu</code> property is now supported.</p></td></tr>
2497<tr><td>v0.2.0</td>
2498<td><p><span>Added in: v0.2.0</span></p></td></tr>
2499</tbody></table>
2500</details>
2501</div>
2502<ul>
2503<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2504</ul>
2505<p>The <code>process.versions</code> property returns an object listing the version strings of
2506Node.js and its dependencies. <code>process.versions.modules</code> indicates the current
2507ABI version, which is increased whenever a C++ API changes. Node.js will refuse
2508to load modules that were compiled against a different module ABI version.</p>
2509<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-property">versions</span>);</code></pre>
2510<p>Will generate an object similar to:</p>
2511<pre><code class="language-console">{ node: '11.13.0',
2512  v8: '7.0.276.38-node.18',
2513  uv: '1.27.0',
2514  zlib: '1.2.11',
2515  brotli: '1.0.7',
2516  ares: '1.15.0',
2517  modules: '67',
2518  nghttp2: '1.34.0',
2519  napi: '4',
2520  llhttp: '1.1.1',
2521  openssl: '1.1.1b',
2522  cldr: '34.0',
2523  icu: '63.1',
2524  tz: '2018e',
2525  unicode: '11.0' }</code></pre>
2526</section><section><h3>Exit codes<span><a class="mark" href="#process_exit_codes" id="process_exit_codes">#</a></span></h3>
2527<p>Node.js will normally exit with a <code>0</code> status code when no more async
2528operations are pending. The following status codes are used in other
2529cases:</p>
2530<ul>
2531<li><code>1</code> <strong>Uncaught Fatal Exception</strong>: There was an uncaught exception,
2532and it was not handled by a domain or an <a href="#process_event_uncaughtexception"><code>'uncaughtException'</code></a> event
2533handler.</li>
2534<li><code>2</code>: Unused (reserved by Bash for builtin misuse)</li>
2535<li><code>3</code> <strong>Internal JavaScript Parse Error</strong>: The JavaScript source code
2536internal in the Node.js bootstrapping process caused a parse error. This
2537is extremely rare, and generally can only happen during development
2538of Node.js itself.</li>
2539<li><code>4</code> <strong>Internal JavaScript Evaluation Failure</strong>: The JavaScript
2540source code internal in the Node.js bootstrapping process failed to
2541return a function value when evaluated. This is extremely rare, and
2542generally can only happen during development of Node.js itself.</li>
2543<li><code>5</code> <strong>Fatal Error</strong>: There was a fatal unrecoverable error in V8.
2544Typically a message will be printed to stderr with the prefix <code>FATAL ERROR</code>.</li>
2545<li><code>6</code> <strong>Non-function Internal Exception Handler</strong>: There was an
2546uncaught exception, but the internal fatal exception handler
2547function was somehow set to a non-function, and could not be called.</li>
2548<li><code>7</code> <strong>Internal Exception Handler Run-Time Failure</strong>: There was an
2549uncaught exception, and the internal fatal exception handler
2550function itself threw an error while attempting to handle it. This
2551can happen, for example, if an <a href="#process_event_uncaughtexception"><code>'uncaughtException'</code></a> or
2552<code>domain.on('error')</code> handler throws an error.</li>
2553<li><code>8</code>: Unused. In previous versions of Node.js, exit code 8 sometimes
2554indicated an uncaught exception.</li>
2555<li><code>9</code> <strong>Invalid Argument</strong>: Either an unknown option was specified,
2556or an option requiring a value was provided without a value.</li>
2557<li><code>10</code> <strong>Internal JavaScript Run-Time Failure</strong>: The JavaScript
2558source code internal in the Node.js bootstrapping process threw an error
2559when the bootstrapping function was called. This is extremely rare,
2560and generally can only happen during development of Node.js itself.</li>
2561<li><code>12</code> <strong>Invalid Debug Argument</strong>: The <code>--inspect</code> and/or <code>--inspect-brk</code>
2562options were set, but the port number chosen was invalid or unavailable.</li>
2563<li><code>13</code> <strong>Unfinished Top-Level Await</strong>: <code>await</code> was used outside of a function
2564in the top-level code, but the passed <code>Promise</code> never resolved.</li>
2565<li><code>>128</code> <strong>Signal Exits</strong>: If Node.js receives a fatal signal such as
2566<code>SIGKILL</code> or <code>SIGHUP</code>, then its exit code will be <code>128</code> plus the
2567value of the signal code. This is a standard POSIX practice, since
2568exit codes are defined to be 7-bit integers, and signal exits set
2569the high-order bit, and then contain the value of the signal code.
2570For example, signal <code>SIGABRT</code> has value <code>6</code>, so the expected exit
2571code will be <code>128</code> + <code>6</code>, or <code>134</code>.</li>
2572</ul></section>
2573        <!-- API END -->
2574      </div>
2575    </div>
2576  </div>
2577  <script>
2578    'use strict';
2579    {
2580      const kCustomPreference = 'customDarkTheme';
2581      const userSettings = sessionStorage.getItem(kCustomPreference);
2582      const themeToggleButton = document.getElementById('theme-toggle-btn');
2583      if (userSettings === null && window.matchMedia) {
2584        const mq = window.matchMedia('(prefers-color-scheme: dark)');
2585        if ('onchange' in mq) {
2586          function mqChangeListener(e) {
2587            document.body.classList.toggle('dark-mode', e.matches);
2588          }
2589          mq.addEventListener('change', mqChangeListener);
2590          if (themeToggleButton) {
2591            themeToggleButton.addEventListener('click', function() {
2592              mq.removeEventListener('change', mqChangeListener);
2593            }, { once: true });
2594          }
2595        }
2596        if (mq.matches) {
2597          document.body.classList.add('dark-mode');
2598        }
2599      } else if (userSettings === 'true') {
2600        document.body.classList.add('dark-mode');
2601      }
2602      if (themeToggleButton) {
2603        themeToggleButton.hidden = false;
2604        themeToggleButton.addEventListener('click', function() {
2605          sessionStorage.setItem(
2606            kCustomPreference,
2607            document.body.classList.toggle('dark-mode')
2608          );
2609        });
2610      }
2611    }
2612  </script>
2613</body>
2614</html>
2615