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