xref: /third_party/node/doc/api/process.html (revision 1cb0ef41)
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="v18.20.1">
7  <title>Process | Node.js v18.20.1 Documentation</title>
8  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
9  <link rel="stylesheet" href="assets/style.css">
10  <link rel="stylesheet" href="assets/hljs.css">
11  <link rel="canonical" href="https://nodejs.org/api/process.html">
12  <script async defer src="assets/api.js" type="text/javascript"></script>
13  <style>@media(max-width:542px){.with-40-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:734px){.with-64-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:550px){.with-41-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:598px){.with-47-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:582px){.with-45-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:566px){.with-43-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:606px){.with-48-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:694px){.with-59-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:750px){.with-66-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:622px){.with-50-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:558px){.with-42-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:574px){.with-44-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}</style>
14</head>
15<body class="alt apidoc" id="api-section-process">
16  <div id="content" class="clearfix">
17    <div id="column2" class="interior">
18      <div id="intro" class="interior">
19        <a href="/" title="Go back to the home page">
20          Node.js
21        </a>
22      </div>
23      <ul>
24<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
25<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
26</ul>
27<hr class="line">
28<ul>
29<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
30<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
31<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
32<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
33<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
34<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
35<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
36<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
37<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
38<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
39<li><a href="console.html" class="nav-console">Console</a></li>
40<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
41<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
42<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
43<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
44<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
45<li><a href="dns.html" class="nav-dns">DNS</a></li>
46<li><a href="domain.html" class="nav-domain">Domain</a></li>
47<li><a href="errors.html" class="nav-errors">Errors</a></li>
48<li><a href="events.html" class="nav-events">Events</a></li>
49<li><a href="fs.html" class="nav-fs">File system</a></li>
50<li><a href="globals.html" class="nav-globals">Globals</a></li>
51<li><a href="http.html" class="nav-http">HTTP</a></li>
52<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
53<li><a href="https.html" class="nav-https">HTTPS</a></li>
54<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
55<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
56<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
57<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
58<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
59<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
60<li><a href="net.html" class="nav-net">Net</a></li>
61<li><a href="os.html" class="nav-os">OS</a></li>
62<li><a href="path.html" class="nav-path">Path</a></li>
63<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
64<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
65<li><a href="process.html" class="nav-process active">Process</a></li>
66<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
67<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
68<li><a href="readline.html" class="nav-readline">Readline</a></li>
69<li><a href="repl.html" class="nav-repl">REPL</a></li>
70<li><a href="report.html" class="nav-report">Report</a></li>
71<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
72<li><a href="stream.html" class="nav-stream">Stream</a></li>
73<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
74<li><a href="test.html" class="nav-test">Test runner</a></li>
75<li><a href="timers.html" class="nav-timers">Timers</a></li>
76<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
77<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
78<li><a href="tty.html" class="nav-tty">TTY</a></li>
79<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
80<li><a href="url.html" class="nav-url">URL</a></li>
81<li><a href="util.html" class="nav-util">Utilities</a></li>
82<li><a href="v8.html" class="nav-v8">V8</a></li>
83<li><a href="vm.html" class="nav-vm">VM</a></li>
84<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
85<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
86<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
87<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
88<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
89</ul>
90<hr class="line">
91<ul>
92<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
93</ul>
94    </div>
95
96    <div id="column1" data-id="process" class="interior">
97      <header class="header">
98        <div class="header-container">
99          <h1>Node.js v18.20.1 documentation</h1>
100          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
101            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
102              <path fill="none" d="M0 0h24v24H0z" />
103              <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"/>
104              <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"/>
105            </svg>
106            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
107              <path d="M0 0h24v24H0z" fill="none" />
108              <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"/>
109            </svg>
110          </button>
111        </div>
112        <div id="gtoc">
113          <ul>
114            <li class="pinned-header">Node.js v18.20.1</li>
115            
116    <li class="picker-header">
117      <a href="#">
118        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
119        Table of contents
120      </a>
121
122      <div class="picker"><div class="toc"><ul>
123<li><a href="#process">Process</a>
124<ul>
125<li><a href="#process-events">Process events</a>
126<ul>
127<li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li>
128<li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li>
129<li><a href="#event-exit">Event: <code>'exit'</code></a></li>
130<li><a href="#event-message">Event: <code>'message'</code></a></li>
131<li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li>
132<li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li>
133<li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a>
134<ul>
135<li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li>
136</ul>
137</li>
138<li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li>
139<li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li>
140<li><a href="#event-warning">Event: <code>'warning'</code></a></li>
141<li><a href="#event-worker">Event: <code>'worker'</code></a>
142<ul>
143<li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li>
144<li><a href="#nodejs-warning-names">Node.js warning names</a></li>
145</ul>
146</li>
147<li><a href="#signal-events">Signal events</a></li>
148</ul>
149</li>
150<li><a href="#processabort"><code>process.abort()</code></a></li>
151<li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li>
152<li><a href="#processarch"><code>process.arch</code></a></li>
153<li><a href="#processargv"><code>process.argv</code></a></li>
154<li><a href="#processargv0"><code>process.argv0</code></a></li>
155<li><a href="#processchannel"><code>process.channel</code></a>
156<ul>
157<li><a href="#processchannelref"><code>process.channel.ref()</code></a></li>
158<li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li>
159</ul>
160</li>
161<li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li>
162<li><a href="#processconfig"><code>process.config</code></a></li>
163<li><a href="#processconnected"><code>process.connected</code></a></li>
164<li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li>
165<li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li>
166<li><a href="#processcwd"><code>process.cwd()</code></a></li>
167<li><a href="#processdebugport"><code>process.debugPort</code></a></li>
168<li><a href="#processdisconnect"><code>process.disconnect()</code></a></li>
169<li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li>
170<li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li>
171<li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a>
172<ul>
173<li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li>
174</ul>
175</li>
176<li><a href="#processenv"><code>process.env</code></a></li>
177<li><a href="#processexecargv"><code>process.execArgv</code></a></li>
178<li><a href="#processexecpath"><code>process.execPath</code></a></li>
179<li><a href="#processexitcode"><code>process.exit([code])</code></a></li>
180<li><a href="#processexitcode_1"><code>process.exitCode</code></a></li>
181<li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li>
182<li><a href="#processgetegid"><code>process.getegid()</code></a></li>
183<li><a href="#processgeteuid"><code>process.geteuid()</code></a></li>
184<li><a href="#processgetgid"><code>process.getgid()</code></a></li>
185<li><a href="#processgetgroups"><code>process.getgroups()</code></a></li>
186<li><a href="#processgetuid"><code>process.getuid()</code></a></li>
187<li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li>
188<li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li>
189<li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li>
190<li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li>
191<li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li>
192<li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li>
193<li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li>
194<li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li>
195<li><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a>
196<ul>
197<li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li>
198</ul>
199</li>
200<li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li>
201<li><a href="#processpid"><code>process.pid</code></a></li>
202<li><a href="#processplatform"><code>process.platform</code></a></li>
203<li><a href="#processppid"><code>process.ppid</code></a></li>
204<li><a href="#processrelease"><code>process.release</code></a></li>
205<li><a href="#processreport"><code>process.report</code></a>
206<ul>
207<li><a href="#processreportcompact"><code>process.report.compact</code></a></li>
208<li><a href="#processreportdirectory"><code>process.report.directory</code></a></li>
209<li><a href="#processreportfilename"><code>process.report.filename</code></a></li>
210<li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li>
211<li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li>
212<li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li>
213<li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li>
214<li><a href="#processreportsignal"><code>process.report.signal</code></a></li>
215<li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li>
216</ul>
217</li>
218<li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li>
219<li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li>
220<li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li>
221<li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li>
222<li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li>
223<li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li>
224<li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li>
225<li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li>
226<li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li>
227<li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li>
228<li><a href="#processstderr"><code>process.stderr</code></a>
229<ul>
230<li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li>
231</ul>
232</li>
233<li><a href="#processstdin"><code>process.stdin</code></a>
234<ul>
235<li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li>
236</ul>
237</li>
238<li><a href="#processstdout"><code>process.stdout</code></a>
239<ul>
240<li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li>
241<li><a href="#a-note-on-process-io">A note on process I/O</a></li>
242</ul>
243</li>
244<li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li>
245<li><a href="#processtitle"><code>process.title</code></a></li>
246<li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li>
247<li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li>
248<li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li>
249<li><a href="#processuptime"><code>process.uptime()</code></a></li>
250<li><a href="#processversion"><code>process.version</code></a></li>
251<li><a href="#processversions"><code>process.versions</code></a></li>
252<li><a href="#exit-codes">Exit codes</a></li>
253</ul>
254</li>
255</ul></div></div>
256    </li>
257  
258            
259    <li class="picker-header">
260      <a href="#">
261        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
262        Index
263      </a>
264
265      <div class="picker"><ul>
266<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
267<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
268
269      <li>
270        <a href="index.html">Index</a>
271      </li>
272    </ul>
273  
274<hr class="line">
275<ul>
276<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
277<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
278<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
279<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
280<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
281<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
282<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
283<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
284<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
285<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
286<li><a href="console.html" class="nav-console">Console</a></li>
287<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
288<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
289<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
290<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
291<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
292<li><a href="dns.html" class="nav-dns">DNS</a></li>
293<li><a href="domain.html" class="nav-domain">Domain</a></li>
294<li><a href="errors.html" class="nav-errors">Errors</a></li>
295<li><a href="events.html" class="nav-events">Events</a></li>
296<li><a href="fs.html" class="nav-fs">File system</a></li>
297<li><a href="globals.html" class="nav-globals">Globals</a></li>
298<li><a href="http.html" class="nav-http">HTTP</a></li>
299<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
300<li><a href="https.html" class="nav-https">HTTPS</a></li>
301<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
302<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
303<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
304<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
305<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
306<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
307<li><a href="net.html" class="nav-net">Net</a></li>
308<li><a href="os.html" class="nav-os">OS</a></li>
309<li><a href="path.html" class="nav-path">Path</a></li>
310<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
311<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
312<li><a href="process.html" class="nav-process active">Process</a></li>
313<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
314<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
315<li><a href="readline.html" class="nav-readline">Readline</a></li>
316<li><a href="repl.html" class="nav-repl">REPL</a></li>
317<li><a href="report.html" class="nav-report">Report</a></li>
318<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
319<li><a href="stream.html" class="nav-stream">Stream</a></li>
320<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
321<li><a href="test.html" class="nav-test">Test runner</a></li>
322<li><a href="timers.html" class="nav-timers">Timers</a></li>
323<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
324<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
325<li><a href="tty.html" class="nav-tty">TTY</a></li>
326<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
327<li><a href="url.html" class="nav-url">URL</a></li>
328<li><a href="util.html" class="nav-util">Utilities</a></li>
329<li><a href="v8.html" class="nav-v8">V8</a></li>
330<li><a href="vm.html" class="nav-vm">VM</a></li>
331<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
332<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
333<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
334<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
335<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
336</ul>
337<hr class="line">
338<ul>
339<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
340</ul></div>
341    </li>
342  
343            
344    <li class="picker-header">
345      <a href="#">
346        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
347        Other versions
348      </a>
349      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/process.html">21.x</a></li>
350<li><a href="https://nodejs.org/docs/latest-v20.x/api/process.html">20.x <b>LTS</b></a></li>
351<li><a href="https://nodejs.org/docs/latest-v19.x/api/process.html">19.x</a></li>
352<li><a href="https://nodejs.org/docs/latest-v18.x/api/process.html">18.x <b>LTS</b></a></li>
353<li><a href="https://nodejs.org/docs/latest-v17.x/api/process.html">17.x</a></li>
354<li><a href="https://nodejs.org/docs/latest-v16.x/api/process.html">16.x</a></li>
355<li><a href="https://nodejs.org/docs/latest-v15.x/api/process.html">15.x</a></li>
356<li><a href="https://nodejs.org/docs/latest-v14.x/api/process.html">14.x</a></li>
357<li><a href="https://nodejs.org/docs/latest-v13.x/api/process.html">13.x</a></li>
358<li><a href="https://nodejs.org/docs/latest-v12.x/api/process.html">12.x</a></li>
359<li><a href="https://nodejs.org/docs/latest-v11.x/api/process.html">11.x</a></li>
360<li><a href="https://nodejs.org/docs/latest-v10.x/api/process.html">10.x</a></li>
361<li><a href="https://nodejs.org/docs/latest-v9.x/api/process.html">9.x</a></li>
362<li><a href="https://nodejs.org/docs/latest-v8.x/api/process.html">8.x</a></li>
363<li><a href="https://nodejs.org/docs/latest-v7.x/api/process.html">7.x</a></li>
364<li><a href="https://nodejs.org/docs/latest-v6.x/api/process.html">6.x</a></li>
365<li><a href="https://nodejs.org/docs/latest-v5.x/api/process.html">5.x</a></li>
366<li><a href="https://nodejs.org/docs/latest-v4.x/api/process.html">4.x</a></li>
367<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/process.html">0.12.x</a></li>
368<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/process.html">0.10.x</a></li></ol></div>
369    </li>
370  
371            <li class="picker-header">
372              <a href="#">
373                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
374                Options
375              </a>
376        
377              <div class="picker">
378                <ul>
379                  <li>
380                    <a href="all.html">View on single page</a>
381                  </li>
382                  <li>
383                    <a href="process.json">View as JSON</a>
384                  </li>
385                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/process.md">Edit on GitHub</a></li>    
386                </ul>
387              </div>
388            </li>
389          </ul>
390        </div>
391        <hr>
392      </header>
393
394      <details id="toc" open><summary>Table of contents</summary><ul>
395<li><a href="#process">Process</a>
396<ul>
397<li><a href="#process-events">Process events</a>
398<ul>
399<li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li>
400<li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li>
401<li><a href="#event-exit">Event: <code>'exit'</code></a></li>
402<li><a href="#event-message">Event: <code>'message'</code></a></li>
403<li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li>
404<li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li>
405<li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a>
406<ul>
407<li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li>
408</ul>
409</li>
410<li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li>
411<li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li>
412<li><a href="#event-warning">Event: <code>'warning'</code></a></li>
413<li><a href="#event-worker">Event: <code>'worker'</code></a>
414<ul>
415<li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li>
416<li><a href="#nodejs-warning-names">Node.js warning names</a></li>
417</ul>
418</li>
419<li><a href="#signal-events">Signal events</a></li>
420</ul>
421</li>
422<li><a href="#processabort"><code>process.abort()</code></a></li>
423<li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li>
424<li><a href="#processarch"><code>process.arch</code></a></li>
425<li><a href="#processargv"><code>process.argv</code></a></li>
426<li><a href="#processargv0"><code>process.argv0</code></a></li>
427<li><a href="#processchannel"><code>process.channel</code></a>
428<ul>
429<li><a href="#processchannelref"><code>process.channel.ref()</code></a></li>
430<li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li>
431</ul>
432</li>
433<li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li>
434<li><a href="#processconfig"><code>process.config</code></a></li>
435<li><a href="#processconnected"><code>process.connected</code></a></li>
436<li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li>
437<li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li>
438<li><a href="#processcwd"><code>process.cwd()</code></a></li>
439<li><a href="#processdebugport"><code>process.debugPort</code></a></li>
440<li><a href="#processdisconnect"><code>process.disconnect()</code></a></li>
441<li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li>
442<li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li>
443<li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a>
444<ul>
445<li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li>
446</ul>
447</li>
448<li><a href="#processenv"><code>process.env</code></a></li>
449<li><a href="#processexecargv"><code>process.execArgv</code></a></li>
450<li><a href="#processexecpath"><code>process.execPath</code></a></li>
451<li><a href="#processexitcode"><code>process.exit([code])</code></a></li>
452<li><a href="#processexitcode_1"><code>process.exitCode</code></a></li>
453<li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li>
454<li><a href="#processgetegid"><code>process.getegid()</code></a></li>
455<li><a href="#processgeteuid"><code>process.geteuid()</code></a></li>
456<li><a href="#processgetgid"><code>process.getgid()</code></a></li>
457<li><a href="#processgetgroups"><code>process.getgroups()</code></a></li>
458<li><a href="#processgetuid"><code>process.getuid()</code></a></li>
459<li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li>
460<li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li>
461<li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li>
462<li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li>
463<li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li>
464<li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li>
465<li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li>
466<li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li>
467<li><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a>
468<ul>
469<li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li>
470</ul>
471</li>
472<li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li>
473<li><a href="#processpid"><code>process.pid</code></a></li>
474<li><a href="#processplatform"><code>process.platform</code></a></li>
475<li><a href="#processppid"><code>process.ppid</code></a></li>
476<li><a href="#processrelease"><code>process.release</code></a></li>
477<li><a href="#processreport"><code>process.report</code></a>
478<ul>
479<li><a href="#processreportcompact"><code>process.report.compact</code></a></li>
480<li><a href="#processreportdirectory"><code>process.report.directory</code></a></li>
481<li><a href="#processreportfilename"><code>process.report.filename</code></a></li>
482<li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li>
483<li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li>
484<li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li>
485<li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li>
486<li><a href="#processreportsignal"><code>process.report.signal</code></a></li>
487<li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li>
488</ul>
489</li>
490<li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li>
491<li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li>
492<li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li>
493<li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li>
494<li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li>
495<li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li>
496<li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li>
497<li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li>
498<li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li>
499<li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li>
500<li><a href="#processstderr"><code>process.stderr</code></a>
501<ul>
502<li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li>
503</ul>
504</li>
505<li><a href="#processstdin"><code>process.stdin</code></a>
506<ul>
507<li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li>
508</ul>
509</li>
510<li><a href="#processstdout"><code>process.stdout</code></a>
511<ul>
512<li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li>
513<li><a href="#a-note-on-process-io">A note on process I/O</a></li>
514</ul>
515</li>
516<li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li>
517<li><a href="#processtitle"><code>process.title</code></a></li>
518<li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li>
519<li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li>
520<li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li>
521<li><a href="#processuptime"><code>process.uptime()</code></a></li>
522<li><a href="#processversion"><code>process.version</code></a></li>
523<li><a href="#processversions"><code>process.versions</code></a></li>
524<li><a href="#exit-codes">Exit codes</a></li>
525</ul>
526</li>
527</ul></details>
528
529      <div id="apicontent">
530        <h2>Process<span><a class="mark" href="#process" id="process">#</a></span><a aria-hidden="true" class="legacy" id="process_process"></a></h2>
531
532
533<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/process.js">lib/process.js</a></p>
534<p>The <code>process</code> object provides information about, and control over, the current
535Node.js process.</p>
536
537<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);</code><button class="copy-button">copy</button></pre>
538<section><h3>Process events<span><a class="mark" href="#process-events" id="process-events">#</a></span><a aria-hidden="true" class="legacy" id="process_process_events"></a></h3>
539<p>The <code>process</code> object is an instance of <a href="events.html#class-eventemitter"><code>EventEmitter</code></a>.</p>
540<h4>Event: <code>'beforeExit'</code><span><a class="mark" href="#event-beforeexit" id="event-beforeexit">#</a></span><a aria-hidden="true" class="legacy" id="process_event_beforeexit"></a></h4>
541<div class="api_metadata">
542<span>Added in: v0.11.12</span>
543</div>
544<p>The <code>'beforeExit'</code> event is emitted when Node.js empties its event loop and has
545no additional work to schedule. Normally, the Node.js process will exit when
546there is no work scheduled, but a listener registered on the <code>'beforeExit'</code>
547event can make asynchronous calls, and thereby cause the Node.js process to
548continue.</p>
549<p>The listener callback function is invoked with the value of
550<a href="#processexitcode_1"><code>process.exitCode</code></a> passed as the only argument.</p>
551<p>The <code>'beforeExit'</code> event is <em>not</em> emitted for conditions causing explicit
552termination, such as calling <a href="#processexitcode"><code>process.exit()</code></a> or uncaught exceptions.</p>
553<p>The <code>'beforeExit'</code> should <em>not</em> be used as an alternative to the <code>'exit'</code> event
554unless the intention is to schedule additional work.</p>
555
556<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
557
558process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
559  <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);
560});
561
562process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
563  <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);
564});
565
566<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>);
567
568<span class="hljs-comment">// Prints:</span>
569<span class="hljs-comment">// This message is displayed first.</span>
570<span class="hljs-comment">// Process beforeExit event with code: 0</span>
571<span class="hljs-comment">// Process exit event with code: 0</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
572
573process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
574  <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);
575});
576
577process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
578  <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);
579});
580
581<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>);
582
583<span class="hljs-comment">// Prints:</span>
584<span class="hljs-comment">// This message is displayed first.</span>
585<span class="hljs-comment">// Process beforeExit event with code: 0</span>
586<span class="hljs-comment">// Process exit event with code: 0</span></code><button class="copy-button">copy</button></pre>
587<h4>Event: <code>'disconnect'</code><span><a class="mark" href="#event-disconnect" id="event-disconnect">#</a></span><a aria-hidden="true" class="legacy" id="process_event_disconnect"></a></h4>
588<div class="api_metadata">
589<span>Added in: v0.7.7</span>
590</div>
591<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
592and <a href="cluster.html">Cluster</a> documentation), the <code>'disconnect'</code> event will be emitted when
593the IPC channel is closed.</p>
594<h4>Event: <code>'exit'</code><span><a class="mark" href="#event-exit" id="event-exit">#</a></span><a aria-hidden="true" class="legacy" id="process_event_exit"></a></h4>
595<div class="api_metadata">
596<span>Added in: v0.1.7</span>
597</div>
598<ul>
599<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>
600</ul>
601<p>The <code>'exit'</code> event is emitted when the Node.js process is about to exit as a
602result of either:</p>
603<ul>
604<li>The <code>process.exit()</code> method being called explicitly;</li>
605<li>The Node.js event loop no longer having any additional work to perform.</li>
606</ul>
607<p>There is no way to prevent the exiting of the event loop at this point, and once
608all <code>'exit'</code> listeners have finished running the Node.js process will terminate.</p>
609<p>The listener callback function is invoked with the exit code specified either
610by the <a href="#processexitcode_1"><code>process.exitCode</code></a> property, or the <code>exitCode</code> argument passed to the
611<a href="#processexitcode"><code>process.exit()</code></a> method.</p>
612
613<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
614
615process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
616  <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>);
617});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
618
619process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
620  <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>);
621});</code><button class="copy-button">copy</button></pre>
622<p>Listener functions <strong>must</strong> only perform <strong>synchronous</strong> operations. The Node.js
623process will exit immediately after calling the <code>'exit'</code> event listeners
624causing any additional work still queued in the event loop to be abandoned.
625In the following example, for instance, the timeout will never occur:</p>
626
627<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
628
629process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
630  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
631    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>);
632  }, <span class="hljs-number">0</span>);
633});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
634
635process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
636  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
637    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>);
638  }, <span class="hljs-number">0</span>);
639});</code><button class="copy-button">copy</button></pre>
640<h4>Event: <code>'message'</code><span><a class="mark" href="#event-message" id="event-message">#</a></span><a aria-hidden="true" class="legacy" id="process_event_message"></a></h4>
641<div class="api_metadata">
642<span>Added in: v0.5.10</span>
643</div>
644<ul>
645<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
646or a serializable primitive value.</li>
647<li><code>sendHandle</code> <a href="net.html#class-netserver" class="type">&#x3C;net.Server></a> | <a href="net.html#class-netsocket" class="type">&#x3C;net.Socket></a> a <a href="net.html#class-netserver"><code>net.Server</code></a> or <a href="net.html#class-netsocket"><code>net.Socket</code></a>
648object, or undefined.</li>
649</ul>
650<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
651and <a href="cluster.html">Cluster</a> documentation), the <code>'message'</code> event is emitted whenever a
652message sent by a parent process using <a href="child_process.html#subprocesssendmessage-sendhandle-options-callback"><code>childprocess.send()</code></a> is received by
653the child process.</p>
654<p>The message goes through serialization and parsing. The resulting message might
655not be the same as what is originally sent.</p>
656<p>If the <code>serialization</code> option was set to <code>advanced</code> used when spawning the
657process, the <code>message</code> argument can contain data that JSON is not able
658to represent.
659See <a href="child_process.html#advanced-serialization">Advanced serialization for <code>child_process</code></a> for more details.</p>
660<h4>Event: <code>'multipleResolves'</code><span><a class="mark" href="#event-multipleresolves" id="event-multipleresolves">#</a></span><a aria-hidden="true" class="legacy" id="process_event_multipleresolves"></a></h4>
661<div class="api_metadata">
662<span>Added in: v10.12.0</span><span>Deprecated since: v17.6.0</span>
663</div>
664<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated</div><p></p>
665<ul>
666<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>
667<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>
668<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
669rejected after the original resolve.</li>
670</ul>
671<p>The <code>'multipleResolves'</code> event is emitted whenever a <code>Promise</code> has been either:</p>
672<ul>
673<li>Resolved more than once.</li>
674<li>Rejected more than once.</li>
675<li>Rejected after resolve.</li>
676<li>Resolved after reject.</li>
677</ul>
678<p>This is useful for tracking potential errors in an application while using the
679<code>Promise</code> constructor, as multiple resolutions are silently swallowed. However,
680the occurrence of this event does not necessarily indicate an error. For
681example, <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>
682<p>Because of the unreliability of the event in cases like the
683<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race"><code>Promise.race()</code></a> example above it has been deprecated.</p>
684
685<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
686
687process.<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> {
688  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason);
689  <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>));
690});
691
692<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
693  <span class="hljs-keyword">try</span> {
694    <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> {
695      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>);
696      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</span>);
697      <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>));
698    });
699  } <span class="hljs-keyword">catch</span> {
700    <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>);
701  }
702}
703
704<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>);
705<span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span>
706<span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span>
707<span class="hljs-comment">//     at Promise (*)</span>
708<span class="hljs-comment">//     at new Promise (&#x3C;anonymous>)</span>
709<span class="hljs-comment">//     at main (*)</span>
710<span class="hljs-comment">// First call</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
711
712process.<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> {
713  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason);
714  <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>));
715});
716
717<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
718  <span class="hljs-keyword">try</span> {
719    <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> {
720      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>);
721      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</span>);
722      <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>));
723    });
724  } <span class="hljs-keyword">catch</span> {
725    <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>);
726  }
727}
728
729<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>);
730<span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span>
731<span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span>
732<span class="hljs-comment">//     at Promise (*)</span>
733<span class="hljs-comment">//     at new Promise (&#x3C;anonymous>)</span>
734<span class="hljs-comment">//     at main (*)</span>
735<span class="hljs-comment">// First call</span></code><button class="copy-button">copy</button></pre>
736<h4>Event: <code>'rejectionHandled'</code><span><a class="mark" href="#event-rejectionhandled" id="event-rejectionhandled">#</a></span><a aria-hidden="true" class="legacy" id="process_event_rejectionhandled"></a></h4>
737<div class="api_metadata">
738<span>Added in: v1.4.1</span>
739</div>
740<ul>
741<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>
742</ul>
743<p>The <code>'rejectionHandled'</code> event is emitted whenever a <code>Promise</code> has been rejected
744and 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
745example) later than one turn of the Node.js event loop.</p>
746<p>The <code>Promise</code> object would have previously been emitted in an
747<code>'unhandledRejection'</code> event, but during the course of processing gained a
748rejection handler.</p>
749<p>There is no notion of a top level for a <code>Promise</code> chain at which rejections can
750always be handled. Being inherently asynchronous in nature, a <code>Promise</code>
751rejection can be handled at a future point in time, possibly much later than
752the event loop turn it takes for the <code>'unhandledRejection'</code> event to be emitted.</p>
753<p>Another way of stating this is that, unlike in synchronous code where there is
754an ever-growing list of unhandled exceptions, with Promises there can be a
755growing-and-shrinking list of unhandled rejections.</p>
756<p>In synchronous code, the <code>'uncaughtException'</code> event is emitted when the list of
757unhandled exceptions grows.</p>
758<p>In asynchronous code, the <code>'unhandledRejection'</code> event is emitted when the list
759of unhandled rejections grows, and the <code>'rejectionHandled'</code> event is emitted
760when the list of unhandled rejections shrinks.</p>
761
762<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
763
764<span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
765process.<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> {
766  unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason);
767});
768process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> {
769  unhandledRejections.<span class="hljs-title function_">delete</span>(promise);
770});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
771
772<span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
773process.<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> {
774  unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason);
775});
776process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> {
777  unhandledRejections.<span class="hljs-title function_">delete</span>(promise);
778});</code><button class="copy-button">copy</button></pre>
779<p>In this example, the <code>unhandledRejections</code> <code>Map</code> will grow and shrink over time,
780reflecting rejections that start unhandled and then become handled. It is
781possible to record such errors in an error log, either periodically (which is
782likely best for long-running application) or upon process exit (which is likely
783most convenient for scripts).</p>
784<h4>Event: <code>'uncaughtException'</code><span><a class="mark" href="#event-uncaughtexception" id="event-uncaughtexception">#</a></span><a aria-hidden="true" class="legacy" id="process_event_uncaughtexception"></a></h4>
785<div class="api_metadata">
786<details class="changelog"><summary>History</summary>
787<table>
788<tbody><tr><th>Version</th><th>Changes</th></tr>
789<tr><td>v12.0.0, v10.17.0</td>
790<td><p>Added the <code>origin</code> argument.</p></td></tr>
791<tr><td>v0.1.18</td>
792<td><p><span>Added in: v0.1.18</span></p></td></tr>
793</tbody></table>
794</details>
795</div>
796<ul>
797<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>
798<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
799rejection or from a synchronous error. Can either be <code>'uncaughtException'</code> or
800<code>'unhandledRejection'</code>. The latter is used when an exception happens in a
801<code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and
802<a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the
803default) and the rejection is not handled, or when a rejection happens during
804the command line entry point's ES module static loading phase.</li>
805</ul>
806<p>The <code>'uncaughtException'</code> event is emitted when an uncaught JavaScript
807exception bubbles all the way back to the event loop. By default, Node.js
808handles such exceptions by printing the stack trace to <code>stderr</code> and exiting
809with code 1, overriding any previously set <a href="#processexitcode_1"><code>process.exitCode</code></a>.
810Adding a handler for the <code>'uncaughtException'</code> event overrides this default
811behavior. Alternatively, change the <a href="#processexitcode_1"><code>process.exitCode</code></a> in the
812<code>'uncaughtException'</code> handler which will result in the process exiting with the
813provided exit code. Otherwise, in the presence of such handler the process will
814exit with 0.</p>
815
816<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
817
818process.<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> {
819  fs.<span class="hljs-title function_">writeSync</span>(
820    process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>,
821    <span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> +
822    <span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>`</span>,
823  );
824});
825
826<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
827  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>);
828}, <span class="hljs-number">500</span>);
829
830<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
831<span class="hljs-title function_">nonexistentFunc</span>();
832<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run.'</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
833
834process.<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> {
835  fs.<span class="hljs-title function_">writeSync</span>(
836    process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>,
837    <span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> +
838    <span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>`</span>,
839  );
840});
841
842<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
843  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>);
844}, <span class="hljs-number">500</span>);
845
846<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
847<span class="hljs-title function_">nonexistentFunc</span>();
848<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run.'</span>);</code><button class="copy-button">copy</button></pre>
849<p>It is possible to monitor <code>'uncaughtException'</code> events without overriding the
850default behavior to exit the process by installing a
851<code>'uncaughtExceptionMonitor'</code> listener.</p>
852<h5>Warning: Using <code>'uncaughtException'</code> correctly<span><a class="mark" href="#warning-using-uncaughtexception-correctly" id="warning-using-uncaughtexception-correctly">#</a></span><a aria-hidden="true" class="legacy" id="process_warning_using_uncaughtexception_correctly"></a></h5>
853<p><code>'uncaughtException'</code> is a crude mechanism for exception handling
854intended to be used only as a last resort. The event <em>should not</em> be used as
855an equivalent to <code>On Error Resume Next</code>. Unhandled exceptions inherently mean
856that an application is in an undefined state. Attempting to resume application
857code without properly recovering from the exception can cause additional
858unforeseen and unpredictable issues.</p>
859<p>Exceptions thrown from within the event handler will not be caught. Instead the
860process will exit with a non-zero exit code and the stack trace will be printed.
861This is to avoid infinite recursion.</p>
862<p>Attempting to resume normally after an uncaught exception can be similar to
863pulling out the power cord when upgrading a computer. Nine out of ten
864times, nothing happens. But the tenth time, the system becomes corrupted.</p>
865<p>The correct use of <code>'uncaughtException'</code> is to perform synchronous cleanup
866of allocated resources (e.g. file descriptors, handles, etc) before shutting
867down the process. <strong>It is not safe to resume normal operation after
868<code>'uncaughtException'</code>.</strong></p>
869<p>To restart a crashed application in a more reliable way, whether
870<code>'uncaughtException'</code> is emitted or not, an external monitor should be employed
871in a separate process to detect application failures and recover or restart as
872needed.</p>
873<h4>Event: <code>'uncaughtExceptionMonitor'</code><span><a class="mark" href="#event-uncaughtexceptionmonitor" id="event-uncaughtexceptionmonitor">#</a></span><a aria-hidden="true" class="legacy" id="process_event_uncaughtexceptionmonitor"></a></h4>
874<div class="api_metadata">
875<span>Added in: v13.7.0, v12.17.0</span>
876</div>
877<ul>
878<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>
879<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
880rejection or from synchronous errors. Can either be <code>'uncaughtException'</code> or
881<code>'unhandledRejection'</code>. The latter is used when an exception happens in a
882<code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and
883<a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the
884default) and the rejection is not handled, or when a rejection happens during
885the command line entry point's ES module static loading phase.</li>
886</ul>
887<p>The <code>'uncaughtExceptionMonitor'</code> event is emitted before an
888<code>'uncaughtException'</code> event is emitted or a hook installed via
889<a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a> is called.</p>
890<p>Installing an <code>'uncaughtExceptionMonitor'</code> listener does not change the behavior
891once an <code>'uncaughtException'</code> event is emitted. The process will
892still crash if no <code>'uncaughtException'</code> listener is installed.</p>
893
894<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
895
896process.<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> {
897  <span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin);
898});
899
900<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
901<span class="hljs-title function_">nonexistentFunc</span>();
902<span class="hljs-comment">// Still crashes Node.js</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
903
904process.<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> {
905  <span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin);
906});
907
908<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
909<span class="hljs-title function_">nonexistentFunc</span>();
910<span class="hljs-comment">// Still crashes Node.js</span></code><button class="copy-button">copy</button></pre>
911<h4>Event: <code>'unhandledRejection'</code><span><a class="mark" href="#event-unhandledrejection" id="event-unhandledrejection">#</a></span><a aria-hidden="true" class="legacy" id="process_event_unhandledrejection"></a></h4>
912<div class="api_metadata">
913<details class="changelog"><summary>History</summary>
914<table>
915<tbody><tr><th>Version</th><th>Changes</th></tr>
916<tr><td>v7.0.0</td>
917<td><p>Not handling <code>Promise</code> rejections is deprecated.</p></td></tr>
918<tr><td>v6.6.0</td>
919<td><p>Unhandled <code>Promise</code> rejections will now emit a process warning.</p></td></tr>
920<tr><td>v1.4.1</td>
921<td><p><span>Added in: v1.4.1</span></p></td></tr>
922</tbody></table>
923</details>
924</div>
925<ul>
926<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
927(typically an <a href="errors.html#class-error"><code>Error</code></a> object).</li>
928<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>
929</ul>
930<p>The <code>'unhandledRejection'</code> event is emitted whenever a <code>Promise</code> is rejected and
931no error handler is attached to the promise within a turn of the event loop.
932When programming with Promises, exceptions are encapsulated as "rejected
933promises". 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
934are propagated through a <code>Promise</code> chain. The <code>'unhandledRejection'</code> event is
935useful for detecting and keeping track of promises that were rejected whose
936rejections have not yet been handled.</p>
937
938<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
939
940process.<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> {
941  <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);
942  <span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span>
943});
944
945somePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
946  <span class="hljs-keyword">return</span> <span class="hljs-title function_">reportToUser</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">pasre</span>(res)); <span class="hljs-comment">// Note the typo (`pasre`)</span>
947}); <span class="hljs-comment">// No `.catch()` or `.then()`</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
948
949process.<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> {
950  <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);
951  <span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span>
952});
953
954somePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
955  <span class="hljs-keyword">return</span> <span class="hljs-title function_">reportToUser</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">pasre</span>(res)); <span class="hljs-comment">// Note the typo (`pasre`)</span>
956}); <span class="hljs-comment">// No `.catch()` or `.then()`</span></code><button class="copy-button">copy</button></pre>
957<p>The following will also trigger the <code>'unhandledRejection'</code> event to be
958emitted:</p>
959
960<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
961
962<span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) {
963  <span class="hljs-comment">// Initially set the loaded status to a rejected promise</span>
964  <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>));
965}
966
967<span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>();
968<span class="hljs-comment">// no .catch or .then on resource.loaded for at least a turn</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
969
970<span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) {
971  <span class="hljs-comment">// Initially set the loaded status to a rejected promise</span>
972  <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>));
973}
974
975<span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>();
976<span class="hljs-comment">// no .catch or .then on resource.loaded for at least a turn</span></code><button class="copy-button">copy</button></pre>
977<p>In this example case, it is possible to track the rejection as a developer error
978as would typically be the case for other <code>'unhandledRejection'</code> events. To
979address such failures, a non-operational
980<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
981<code>resource.loaded</code>, which would prevent the <code>'unhandledRejection'</code> event from
982being emitted.</p>
983<h4>Event: <code>'warning'</code><span><a class="mark" href="#event-warning" id="event-warning">#</a></span><a aria-hidden="true" class="legacy" id="process_event_warning"></a></h4>
984<div class="api_metadata">
985<span>Added in: v6.0.0</span>
986</div>
987<ul>
988<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:
989<ul>
990<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>
991<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>
992<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
993was issued.</li>
994</ul>
995</li>
996</ul>
997<p>The <code>'warning'</code> event is emitted whenever Node.js emits a process warning.</p>
998<p>A process warning is similar to an error in that it describes exceptional
999conditions that are being brought to the user's attention. However, warnings
1000are not part of the normal Node.js and JavaScript error handling flow.
1001Node.js can emit warnings whenever it detects bad coding practices that could
1002lead to sub-optimal application performance, bugs, or security vulnerabilities.</p>
1003
1004<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1005
1006process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1007  <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>
1008  <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>
1009  <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>
1010});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1011
1012process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1013  <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>
1014  <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>
1015  <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>
1016});</code><button class="copy-button">copy</button></pre>
1017<p>By default, Node.js will print process warnings to <code>stderr</code>. The <code>--no-warnings</code>
1018command-line option can be used to suppress the default console output but the
1019<code>'warning'</code> event will still be emitted by the <code>process</code> object.</p>
1020<p>The following example illustrates the warning that is printed to <code>stderr</code> when
1021too many listeners have been added to an event:</p>
1022<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span>
1023<span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
1024<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
1025<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
1026<span class="hljs-meta prompt_">> </span><span class="language-bash">(node:38638) MaxListenersExceededWarning: Possible EventEmitter memory leak</span>
1027detected. 2 foo listeners added. Use emitter.setMaxListeners() to increase limit</code> <button class="copy-button">copy</button></pre>
1028<p>In contrast, the following example turns off the default warning output and
1029adds a custom handler to the <code>'warning'</code> event:</p>
1030<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node --no-warnings</span>
1031<span class="hljs-meta prompt_">> </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>
1032<span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
1033<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
1034<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
1035<span class="hljs-meta prompt_">> </span><span class="language-bash">Do not <span class="hljs-keyword">do</span> that!</span></code> <button class="copy-button">copy</button></pre>
1036<p>The <code>--trace-warnings</code> command-line option can be used to have the default
1037console output for warnings include the full stack trace of the warning.</p>
1038<p>Launching Node.js using the <code>--throw-deprecation</code> command-line flag will
1039cause custom deprecation warnings to be thrown as exceptions.</p>
1040<p>Using the <code>--trace-deprecation</code> command-line flag will cause the custom
1041deprecation to be printed to <code>stderr</code> along with the stack trace.</p>
1042<p>Using the <code>--no-deprecation</code> command-line flag will suppress all reporting
1043of the custom deprecation.</p>
1044<p>The <code>*-deprecation</code> command-line flags only affect warnings that use the name
1045<code>'DeprecationWarning'</code>.</p>
1046<h4>Event: <code>'worker'</code><span><a class="mark" href="#event-worker" id="event-worker">#</a></span><a aria-hidden="true" class="legacy" id="process_event_worker"></a></h4>
1047<div class="api_metadata">
1048<span>Added in: v16.2.0, v14.18.0</span>
1049</div>
1050<ul>
1051<li><code>worker</code> <a href="worker_threads.html#class-worker" class="type">&#x3C;Worker></a> The <a href="worker_threads.html#class-worker" class="type">&#x3C;Worker></a> that was created.</li>
1052</ul>
1053<p>The <code>'worker'</code> event is emitted after a new <a href="worker_threads.html#class-worker" class="type">&#x3C;Worker></a> thread has been created.</p>
1054<h5>Emitting custom warnings<span><a class="mark" href="#emitting-custom-warnings" id="emitting-custom-warnings">#</a></span><a aria-hidden="true" class="legacy" id="process_emitting_custom_warnings"></a></h5>
1055<p>See the <a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning()</code></a> method for issuing
1056custom or application-specific warnings.</p>
1057<h5>Node.js warning names<span><a class="mark" href="#nodejs-warning-names" id="nodejs-warning-names">#</a></span><a aria-hidden="true" class="legacy" id="process_node_js_warning_names"></a></h5>
1058<p>There are no strict guidelines for warning types (as identified by the <code>name</code>
1059property) emitted by Node.js. New types of warnings can be added at any time.
1060A few of the warning types that are most common include:</p>
1061<ul>
1062<li><code>'DeprecationWarning'</code> - Indicates use of a deprecated Node.js API or feature.
1063Such warnings must include a <code>'code'</code> property identifying the
1064<a href="deprecations.html">deprecation code</a>.</li>
1065<li><code>'ExperimentalWarning'</code> - Indicates use of an experimental Node.js API or
1066feature. Such features must be used with caution as they may change at any
1067time and are not subject to the same strict semantic-versioning and long-term
1068support policies as supported features.</li>
1069<li><code>'MaxListenersExceededWarning'</code> - Indicates that too many listeners for a
1070given event have been registered on either an <code>EventEmitter</code> or <code>EventTarget</code>.
1071This is often an indication of a memory leak.</li>
1072<li><code>'TimeoutOverflowWarning'</code> - Indicates that a numeric value that cannot fit
1073within a 32-bit signed integer has been provided to either the <code>setTimeout()</code>
1074or <code>setInterval()</code> functions.</li>
1075<li><code>'UnsupportedWarning'</code> - Indicates use of an unsupported option or feature
1076that will be ignored rather than treated as an error. One example is use of
1077the HTTP response status message when using the HTTP/2 compatibility API.</li>
1078</ul>
1079<h4>Signal events<span><a class="mark" href="#signal-events" id="signal-events">#</a></span><a aria-hidden="true" class="legacy" id="process_signal_events"></a></h4>
1080
1081
1082<p>Signal events will be emitted when the Node.js process receives a signal. Please
1083refer 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
1084<code>'SIGINT'</code>, <code>'SIGHUP'</code>, etc.</p>
1085<p>Signals are not available on <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
1086<p>The signal handler will receive the signal's name (<code>'SIGINT'</code>,
1087<code>'SIGTERM'</code>, etc.) as the first argument.</p>
1088<p>The name of each event will be the uppercase common name for the signal (e.g.
1089<code>'SIGINT'</code> for <code>SIGINT</code> signals).</p>
1090
1091<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1092
1093<span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span>
1094process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>();
1095
1096process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> {
1097  <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>);
1098});
1099
1100<span class="hljs-comment">// Using a single function to handle multiple signals</span>
1101<span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) {
1102  <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>);
1103}
1104
1105process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle);
1106process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGTERM'</span>, handle);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1107
1108<span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span>
1109process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>();
1110
1111process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> {
1112  <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>);
1113});
1114
1115<span class="hljs-comment">// Using a single function to handle multiple signals</span>
1116<span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) {
1117  <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>);
1118}
1119
1120process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle);
1121process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGTERM'</span>, handle);</code><button class="copy-button">copy</button></pre>
1122<ul>
1123<li><code>'SIGUSR1'</code> is reserved by Node.js to start the <a href="debugger.html">debugger</a>. It's possible to
1124install a listener but doing so might interfere with the debugger.</li>
1125<li><code>'SIGTERM'</code> and <code>'SIGINT'</code> have default handlers on non-Windows platforms that
1126reset the terminal mode before exiting with code <code>128 + signal number</code>. If one
1127of these signals has a listener installed, its default behavior will be
1128removed (Node.js will no longer exit).</li>
1129<li><code>'SIGPIPE'</code> is ignored by default. It can have a listener installed.</li>
1130<li><code>'SIGHUP'</code> is generated on Windows when the console window is closed, and on
1131other 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
1132listener installed, however Node.js will be unconditionally terminated by
1133Windows about 10 seconds later. On non-Windows platforms, the default
1134behavior of <code>SIGHUP</code> is to terminate Node.js, but once a listener has been
1135installed its default behavior will be removed.</li>
1136<li><code>'SIGTERM'</code> is not supported on Windows, it can be listened on.</li>
1137<li><code>'SIGINT'</code> from the terminal is supported on all platforms, and can usually be
1138generated with <kbd>Ctrl</kbd>+<kbd>C</kbd> (though this may be configurable).
1139It is not generated when <a href="tty.html#readstreamsetrawmodemode">terminal raw mode</a> is enabled
1140and <kbd>Ctrl</kbd>+<kbd>C</kbd> is used.</li>
1141<li><code>'SIGBREAK'</code> is delivered on Windows when <kbd>Ctrl</kbd>+<kbd>Break</kbd> is
1142pressed. On non-Windows platforms, it can be listened on, but there is no way
1143to send or generate it.</li>
1144<li><code>'SIGWINCH'</code> is delivered when the console has been resized. On Windows, this
1145will only happen on write to the console when the cursor is being moved, or
1146when a readable tty is used in raw mode.</li>
1147<li><code>'SIGKILL'</code> cannot have a listener installed, it will unconditionally
1148terminate Node.js on all platforms.</li>
1149<li><code>'SIGSTOP'</code> cannot have a listener installed.</li>
1150<li><code>'SIGBUS'</code>, <code>'SIGFPE'</code>, <code>'SIGSEGV'</code>, and <code>'SIGILL'</code>, when not raised
1151artificially 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
1152which it is not safe to call JS listeners. Doing so might cause the process
1153to stop responding.</li>
1154<li><code>0</code> can be sent to test for the existence of a process, it has no effect if
1155the process exists, but will throw an error if the process does not exist.</li>
1156</ul>
1157<p>Windows does not support signals so has no equivalent to termination by signal,
1158but Node.js offers some emulation with <a href="#processkillpid-signal"><code>process.kill()</code></a>, and
1159<a href="child_process.html#subprocesskillsignal"><code>subprocess.kill()</code></a>:</p>
1160<ul>
1161<li>Sending <code>SIGINT</code>, <code>SIGTERM</code>, and <code>SIGKILL</code> will cause the unconditional
1162termination of the target process, and afterwards, subprocess will report that
1163the process was terminated by signal.</li>
1164<li>Sending signal <code>0</code> can be used as a platform independent way to test for the
1165existence of a process.</li>
1166</ul>
1167</section><section><h3><code>process.abort()</code><span><a class="mark" href="#processabort" id="processabort">#</a></span><a aria-hidden="true" class="legacy" id="process_process_abort"></a></h3>
1168<div class="api_metadata">
1169<span>Added in: v0.7.0</span>
1170</div>
1171<p>The <code>process.abort()</code> method causes the Node.js process to exit immediately and
1172generate a core file.</p>
1173<p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
1174</section><section><h3><code>process.allowedNodeEnvironmentFlags</code><span><a class="mark" href="#processallowednodeenvironmentflags" id="processallowednodeenvironmentflags">#</a></span><a aria-hidden="true" class="legacy" id="process_process_allowednodeenvironmentflags"></a></h3>
1175<div class="api_metadata">
1176<span>Added in: v10.10.0</span>
1177</div>
1178<ul>
1179<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set" class="type">&#x3C;Set></a></li>
1180</ul>
1181<p>The <code>process.allowedNodeEnvironmentFlags</code> property is a special,
1182read-only <code>Set</code> of flags allowable within the <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a>
1183environment variable.</p>
1184<p><code>process.allowedNodeEnvironmentFlags</code> extends <code>Set</code>, but overrides
1185<code>Set.prototype.has</code> to recognize several different possible flag
1186representations. <code>process.allowedNodeEnvironmentFlags.has()</code> will
1187return <code>true</code> in the following cases:</p>
1188<ul>
1189<li>Flags may omit leading single (<code>-</code>) or double (<code>--</code>) dashes; e.g.,
1190<code>inspect-brk</code> for <code>--inspect-brk</code>, or <code>r</code> for <code>-r</code>.</li>
1191<li>Flags passed through to V8 (as listed in <code>--v8-options</code>) may replace
1192one or more <em>non-leading</em> dashes for an underscore, or vice-versa;
1193e.g., <code>--perf_basic_prof</code>, <code>--perf-basic-prof</code>, <code>--perf_basic-prof</code>,
1194etc.</li>
1195<li>Flags may contain one or more equals (<code>=</code>) characters; all
1196characters after and including the first equals will be ignored;
1197e.g., <code>--stack-trace-limit=100</code>.</li>
1198<li>Flags <em>must</em> be allowable within <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a>.</li>
1199</ul>
1200<p>When iterating over <code>process.allowedNodeEnvironmentFlags</code>, flags will
1201appear only <em>once</em>; each will begin with one or more dashes. Flags
1202passed through to V8 will contain underscores instead of non-leading
1203dashes:</p>
1204
1205<pre class="with-64-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { allowedNodeEnvironmentFlags } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1206
1207allowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> {
1208  <span class="hljs-comment">// -r</span>
1209  <span class="hljs-comment">// --inspect-brk</span>
1210  <span class="hljs-comment">// --abort_on_uncaught_exception</span>
1211  <span class="hljs-comment">// ...</span>
1212});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { allowedNodeEnvironmentFlags } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1213
1214allowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> {
1215  <span class="hljs-comment">// -r</span>
1216  <span class="hljs-comment">// --inspect-brk</span>
1217  <span class="hljs-comment">// --abort_on_uncaught_exception</span>
1218  <span class="hljs-comment">// ...</span>
1219});</code><button class="copy-button">copy</button></pre>
1220<p>The methods <code>add()</code>, <code>clear()</code>, and <code>delete()</code> of
1221<code>process.allowedNodeEnvironmentFlags</code> do nothing, and will fail
1222silently.</p>
1223<p>If Node.js was compiled <em>without</em> <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a> support (shown in
1224<a href="#processconfig"><code>process.config</code></a>), <code>process.allowedNodeEnvironmentFlags</code> will
1225contain what <em>would have</em> been allowable.</p>
1226</section><section><h3><code>process.arch</code><span><a class="mark" href="#processarch" id="processarch">#</a></span><a aria-hidden="true" class="legacy" id="process_process_arch"></a></h3>
1227<div class="api_metadata">
1228<span>Added in: v0.5.0</span>
1229</div>
1230<ul>
1231<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1232</ul>
1233<p>The operating system CPU architecture for which the Node.js binary was compiled.
1234Possible values are: <code>'arm'</code>, <code>'arm64'</code>, <code>'ia32'</code>, <code>'mips'</code>,<code>'mipsel'</code>, <code>'ppc'</code>,
1235<code>'ppc64'</code>, <code>'s390'</code>, <code>'s390x'</code>, and <code>'x64'</code>.</p>
1236
1237<pre class="with-41-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { arch } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1238
1239<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">${arch}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { arch } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1240
1241<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">${arch}</span>`</span>);</code><button class="copy-button">copy</button></pre>
1242</section><section><h3><code>process.argv</code><span><a class="mark" href="#processargv" id="processargv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_argv"></a></h3>
1243<div class="api_metadata">
1244<span>Added in: v0.1.27</span>
1245</div>
1246<ul>
1247<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
1248</ul>
1249<p>The <code>process.argv</code> property returns an array containing the command-line
1250arguments passed when the Node.js process was launched. The first element will
1251be <a href="#processexecpath"><code>process.execPath</code></a>. See <code>process.argv0</code> if access to the original value
1252of <code>argv[0]</code> is needed. The second element will be the path to the JavaScript
1253file being executed. The remaining elements will be any additional command-line
1254arguments.</p>
1255<p>For example, assuming the following script for <code>process-args.js</code>:</p>
1256
1257<pre class="with-41-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { argv } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1258
1259<span class="hljs-comment">// print process.argv</span>
1260argv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> {
1261  <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>);
1262});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { argv } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1263
1264<span class="hljs-comment">// print process.argv</span>
1265argv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> {
1266  <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>);
1267});</code><button class="copy-button">copy</button></pre>
1268<p>Launching the Node.js process as:</p>
1269<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node process-args.js one two=three four</span></code> <button class="copy-button">copy</button></pre>
1270<p>Would generate the output:</p>
1271<pre><code class="language-text">0: /usr/local/bin/node
12721: /Users/mjr/work/node/process-args.js
12732: one
12743: two=three
12754: four</code> <button class="copy-button">copy</button></pre>
1276</section><section><h3><code>process.argv0</code><span><a class="mark" href="#processargv0" id="processargv0">#</a></span><a aria-hidden="true" class="legacy" id="process_process_argv0"></a></h3>
1277<div class="api_metadata">
1278<span>Added in: v6.4.0</span>
1279</div>
1280<ul>
1281<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1282</ul>
1283<p>The <code>process.argv0</code> property stores a read-only copy of the original value of
1284<code>argv[0]</code> passed when Node.js starts.</p>
1285<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">bash -c <span class="hljs-string">'exec -a customArgv0 ./node'</span></span>
1286<span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv[0]</span>
1287'/Volumes/code/external/node/out/Release/node'
1288<span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv0</span>
1289'customArgv0'</code> <button class="copy-button">copy</button></pre>
1290</section><section><h3><code>process.channel</code><span><a class="mark" href="#processchannel" id="processchannel">#</a></span><a aria-hidden="true" class="legacy" id="process_process_channel"></a></h3>
1291<div class="api_metadata">
1292<details class="changelog"><summary>History</summary>
1293<table>
1294<tbody><tr><th>Version</th><th>Changes</th></tr>
1295<tr><td>v14.0.0</td>
1296<td><p>The object no longer accidentally exposes native C++ bindings.</p></td></tr>
1297<tr><td>v7.1.0</td>
1298<td><p><span>Added in: v7.1.0</span></p></td></tr>
1299</tbody></table>
1300</details>
1301</div>
1302<ul>
1303<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1304</ul>
1305<p>If the Node.js process was spawned with an IPC channel (see the
1306<a href="child_process.html">Child Process</a> documentation), the <code>process.channel</code>
1307property is a reference to the IPC channel. If no IPC channel exists, this
1308property is <code>undefined</code>.</p>
1309<h4><code>process.channel.ref()</code><span><a class="mark" href="#processchannelref" id="processchannelref">#</a></span><a aria-hidden="true" class="legacy" id="process_process_channel_ref"></a></h4>
1310<div class="api_metadata">
1311<span>Added in: v7.1.0</span>
1312</div>
1313<p>This method makes the IPC channel keep the event loop of the process
1314running if <code>.unref()</code> has been called before.</p>
1315<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
1316listeners on the <code>process</code> object. However, this method can be used to
1317explicitly request a specific behavior.</p>
1318<h4><code>process.channel.unref()</code><span><a class="mark" href="#processchannelunref" id="processchannelunref">#</a></span><a aria-hidden="true" class="legacy" id="process_process_channel_unref"></a></h4>
1319<div class="api_metadata">
1320<span>Added in: v7.1.0</span>
1321</div>
1322<p>This method makes the IPC channel not keep the event loop of the process
1323running, and lets it finish even while the channel is open.</p>
1324<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
1325listeners on the <code>process</code> object. However, this method can be used to
1326explicitly request a specific behavior.</p>
1327</section><section><h3><code>process.chdir(directory)</code><span><a class="mark" href="#processchdirdirectory" id="processchdirdirectory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_chdir_directory"></a></h3>
1328<div class="api_metadata">
1329<span>Added in: v0.1.17</span>
1330</div>
1331<ul>
1332<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>
1333</ul>
1334<p>The <code>process.chdir()</code> method changes the current working directory of the
1335Node.js process or throws an exception if doing so fails (for instance, if
1336the specified <code>directory</code> does not exist).</p>
1337
1338<pre class="with-47-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { chdir, cwd } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1339
1340<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Starting directory: <span class="hljs-subst">${cwd()}</span>`</span>);
1341<span class="hljs-keyword">try</span> {
1342  <span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>);
1343  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New directory: <span class="hljs-subst">${cwd()}</span>`</span>);
1344} <span class="hljs-keyword">catch</span> (err) {
1345  <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>);
1346}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { chdir, cwd } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1347
1348<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Starting directory: <span class="hljs-subst">${cwd()}</span>`</span>);
1349<span class="hljs-keyword">try</span> {
1350  <span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>);
1351  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New directory: <span class="hljs-subst">${cwd()}</span>`</span>);
1352} <span class="hljs-keyword">catch</span> (err) {
1353  <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>);
1354}</code><button class="copy-button">copy</button></pre>
1355<p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
1356</section><section><h3><code>process.config</code><span><a class="mark" href="#processconfig" id="processconfig">#</a></span><a aria-hidden="true" class="legacy" id="process_process_config"></a></h3>
1357<div class="api_metadata">
1358<details class="changelog"><summary>History</summary>
1359<table>
1360<tbody><tr><th>Version</th><th>Changes</th></tr>
1361<tr><td>v16.0.0</td>
1362<td><p>Modifying process.config has been deprecated.</p></td></tr>
1363<tr><td>v0.7.7</td>
1364<td><p><span>Added in: v0.7.7</span></p></td></tr>
1365</tbody></table>
1366</details>
1367</div>
1368<ul>
1369<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1370</ul>
1371<p>The <code>process.config</code> property returns an <code>Object</code> containing the JavaScript
1372representation of the configure options used to compile the current Node.js
1373executable. This is the same as the <code>config.gypi</code> file that was produced when
1374running the <code>./configure</code> script.</p>
1375<p>An example of the possible output looks like:</p>
1376<!-- eslint-skip -->
1377<pre><code class="language-js">{
1378  <span class="hljs-attr">target_defaults</span>:
1379   { <span class="hljs-attr">cflags</span>: [],
1380     <span class="hljs-attr">default_configuration</span>: <span class="hljs-string">'Release'</span>,
1381     <span class="hljs-attr">defines</span>: [],
1382     <span class="hljs-attr">include_dirs</span>: [],
1383     <span class="hljs-attr">libraries</span>: [] },
1384  <span class="hljs-attr">variables</span>:
1385   {
1386     <span class="hljs-attr">host_arch</span>: <span class="hljs-string">'x64'</span>,
1387     <span class="hljs-attr">napi_build_version</span>: <span class="hljs-number">5</span>,
1388     <span class="hljs-attr">node_install_npm</span>: <span class="hljs-string">'true'</span>,
1389     <span class="hljs-attr">node_prefix</span>: <span class="hljs-string">''</span>,
1390     <span class="hljs-attr">node_shared_cares</span>: <span class="hljs-string">'false'</span>,
1391     <span class="hljs-attr">node_shared_http_parser</span>: <span class="hljs-string">'false'</span>,
1392     <span class="hljs-attr">node_shared_libuv</span>: <span class="hljs-string">'false'</span>,
1393     <span class="hljs-attr">node_shared_zlib</span>: <span class="hljs-string">'false'</span>,
1394     <span class="hljs-attr">node_use_dtrace</span>: <span class="hljs-string">'false'</span>,
1395     <span class="hljs-attr">node_use_openssl</span>: <span class="hljs-string">'true'</span>,
1396     <span class="hljs-attr">node_shared_openssl</span>: <span class="hljs-string">'false'</span>,
1397     <span class="hljs-attr">strict_aliasing</span>: <span class="hljs-string">'true'</span>,
1398     <span class="hljs-attr">target_arch</span>: <span class="hljs-string">'x64'</span>,
1399     <span class="hljs-attr">v8_use_snapshot</span>: <span class="hljs-number">1</span>
1400   }
1401}</code> <button class="copy-button">copy</button></pre>
1402<p>The <code>process.config</code> property is <strong>not</strong> read-only and there are existing
1403modules in the ecosystem that are known to extend, modify, or entirely replace
1404the value of <code>process.config</code>.</p>
1405<p>Modifying the <code>process.config</code> property, or any child-property of the
1406<code>process.config</code> object has been deprecated. The <code>process.config</code> will be made
1407read-only in a future release.</p>
1408</section><section><h3><code>process.connected</code><span><a class="mark" href="#processconnected" id="processconnected">#</a></span><a aria-hidden="true" class="legacy" id="process_process_connected"></a></h3>
1409<div class="api_metadata">
1410<span>Added in: v0.7.2</span>
1411</div>
1412<ul>
1413<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1414</ul>
1415<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
1416and <a href="cluster.html">Cluster</a> documentation), the <code>process.connected</code> property will return
1417<code>true</code> so long as the IPC channel is connected and will return <code>false</code> after
1418<code>process.disconnect()</code> is called.</p>
1419<p>Once <code>process.connected</code> is <code>false</code>, it is no longer possible to send messages
1420over the IPC channel using <code>process.send()</code>.</p>
1421</section><section><h3><code>process.constrainedMemory()</code><span><a class="mark" href="#processconstrainedmemory" id="processconstrainedmemory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_constrainedmemory"></a></h3>
1422<div class="api_metadata">
1423<span>Added in: v18.15.0</span>
1424</div>
1425<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
1426<ul>
1427<li><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#Undefined_type" class="type">&#x3C;undefined></a></li>
1428</ul>
1429<p>Gets the amount of memory available to the process (in bytes) based on
1430limits imposed by the OS. If there is no such constraint, or the constraint
1431is unknown, <code>undefined</code> is returned.</p>
1432<p>See <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_get_constrained_memory"><code>uv_get_constrained_memory</code></a> for more
1433information.</p>
1434</section><section><h3><code>process.cpuUsage([previousValue])</code><span><a class="mark" href="#processcpuusagepreviousvalue" id="processcpuusagepreviousvalue">#</a></span><a aria-hidden="true" class="legacy" id="process_process_cpuusage_previousvalue"></a></h3>
1435<div class="api_metadata">
1436<span>Added in: v6.1.0</span>
1437</div>
1438<ul>
1439<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
1440<code>process.cpuUsage()</code></li>
1441<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1442<ul>
1443<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>
1444<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>
1445</ul>
1446</li>
1447</ul>
1448<p>The <code>process.cpuUsage()</code> method returns the user and system CPU time usage of
1449the current process, in an object with properties <code>user</code> and <code>system</code>, whose
1450values are microsecond values (millionth of a second). These values measure time
1451spent in user and system code respectively, and may end up being greater than
1452actual elapsed time if multiple CPU cores are performing work for this process.</p>
1453<p>The result of a previous call to <code>process.cpuUsage()</code> can be passed as the
1454argument to the function, to get a diff reading.</p>
1455
1456<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { cpuUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1457
1458<span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>();
1459<span class="hljs-comment">// { user: 38579, system: 6986 }</span>
1460
1461<span class="hljs-comment">// spin the CPU for 500 milliseconds</span>
1462<span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>();
1463<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>);
1464
1465<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage));
1466<span class="hljs-comment">// { user: 514883, system: 11226 }</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { cpuUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1467
1468<span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>();
1469<span class="hljs-comment">// { user: 38579, system: 6986 }</span>
1470
1471<span class="hljs-comment">// spin the CPU for 500 milliseconds</span>
1472<span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>();
1473<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>);
1474
1475<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage));
1476<span class="hljs-comment">// { user: 514883, system: 11226 }</span></code><button class="copy-button">copy</button></pre>
1477</section><section><h3><code>process.cwd()</code><span><a class="mark" href="#processcwd" id="processcwd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_cwd"></a></h3>
1478<div class="api_metadata">
1479<span>Added in: v0.1.8</span>
1480</div>
1481<ul>
1482<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1483</ul>
1484<p>The <code>process.cwd()</code> method returns the current working directory of the Node.js
1485process.</p>
1486
1487<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { cwd } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1488
1489<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current directory: <span class="hljs-subst">${cwd()}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { cwd } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1490
1491<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current directory: <span class="hljs-subst">${cwd()}</span>`</span>);</code><button class="copy-button">copy</button></pre>
1492</section><section><h3><code>process.debugPort</code><span><a class="mark" href="#processdebugport" id="processdebugport">#</a></span><a aria-hidden="true" class="legacy" id="process_process_debugport"></a></h3>
1493<div class="api_metadata">
1494<span>Added in: v0.7.2</span>
1495</div>
1496<ul>
1497<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1498</ul>
1499<p>The port used by the Node.js debugger when enabled.</p>
1500
1501<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1502
1503process.<span class="hljs-property">debugPort</span> = <span class="hljs-number">5858</span>;</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1504
1505process.<span class="hljs-property">debugPort</span> = <span class="hljs-number">5858</span>;</code><button class="copy-button">copy</button></pre>
1506</section><section><h3><code>process.disconnect()</code><span><a class="mark" href="#processdisconnect" id="processdisconnect">#</a></span><a aria-hidden="true" class="legacy" id="process_process_disconnect"></a></h3>
1507<div class="api_metadata">
1508<span>Added in: v0.7.2</span>
1509</div>
1510<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
1511and <a href="cluster.html">Cluster</a> documentation), the <code>process.disconnect()</code> method will close the
1512IPC channel to the parent process, allowing the child process to exit gracefully
1513once there are no other connections keeping it alive.</p>
1514<p>The effect of calling <code>process.disconnect()</code> is the same as calling
1515<a href="child_process.html#subprocessdisconnect"><code>ChildProcess.disconnect()</code></a> from the parent process.</p>
1516<p>If the Node.js process was not spawned with an IPC channel,
1517<code>process.disconnect()</code> will be <code>undefined</code>.</p>
1518</section><section><h3><code>process.dlopen(module, filename[, flags])</code><span><a class="mark" href="#processdlopenmodule-filename-flags" id="processdlopenmodule-filename-flags">#</a></span><a aria-hidden="true" class="legacy" id="process_process_dlopen_module_filename_flags"></a></h3>
1519<div class="api_metadata">
1520<details class="changelog"><summary>History</summary>
1521<table>
1522<tbody><tr><th>Version</th><th>Changes</th></tr>
1523<tr><td>v9.0.0</td>
1524<td><p>Added support for the <code>flags</code> argument.</p></td></tr>
1525<tr><td>v0.1.16</td>
1526<td><p><span>Added in: v0.1.16</span></p></td></tr>
1527</tbody></table>
1528</details>
1529</div>
1530<ul>
1531<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>
1532<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>
1533<li><code>flags</code> <a href="os.html#dlopen-constants" class="type">&#x3C;os.constants.dlopen></a> <strong>Default:</strong> <code>os.constants.dlopen.RTLD_LAZY</code></li>
1534</ul>
1535<p>The <code>process.dlopen()</code> method allows dynamically loading shared objects. It is
1536primarily used by <code>require()</code> to load C++ Addons, and should not be used
1537directly, except in special cases. In other words, <a href="globals.html#require"><code>require()</code></a> should be
1538preferred over <code>process.dlopen()</code> unless there are specific reasons such as
1539custom dlopen flags or loading from ES modules.</p>
1540<p>The <code>flags</code> argument is an integer that allows to specify dlopen
1541behavior. See the <a href="os.html#dlopen-constants"><code>os.constants.dlopen</code></a> documentation for details.</p>
1542<p>An important requirement when calling <code>process.dlopen()</code> is that the <code>module</code>
1543instance must be passed. Functions exported by the C++ Addon are then
1544accessible via <code>module.exports</code>.</p>
1545<p>The example below shows how to load a C++ Addon, named <code>local.node</code>,
1546that exports a <code>foo</code> function. All the symbols are loaded before
1547the call returns, by passing the <code>RTLD_NOW</code> constant. In this example
1548the constant is assumed to be available.</p>
1549
1550<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { dlopen } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1551<span class="hljs-keyword">import</span> { constants } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:os'</span>;
1552<span class="hljs-keyword">import</span> { fileURLToPath } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:url'</span>;
1553
1554<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} };
1555<span class="hljs-title function_">dlopen</span>(<span class="hljs-variable language_">module</span>, <span class="hljs-title function_">fileURLToPath</span>(<span class="hljs-keyword">new</span> <span class="hljs-title function_">URL</span>(<span class="hljs-string">'local.node'</span>, <span class="hljs-keyword">import</span>.<span class="hljs-property">meta</span>.<span class="hljs-property">url</span>)),
1556       constants.<span class="hljs-property">dlopen</span>.<span class="hljs-property">RTLD_NOW</span>);
1557<span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span>.<span class="hljs-title function_">foo</span>();</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { dlopen } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1558<span class="hljs-keyword">const</span> { constants } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:os'</span>);
1559<span class="hljs-keyword">const</span> { join } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:path'</span>);
1560
1561<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} };
1562<span class="hljs-title function_">dlopen</span>(<span class="hljs-variable language_">module</span>, <span class="hljs-title function_">join</span>(__dirname, <span class="hljs-string">'local.node'</span>), constants.<span class="hljs-property">dlopen</span>.<span class="hljs-property">RTLD_NOW</span>);
1563<span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span>.<span class="hljs-title function_">foo</span>();</code><button class="copy-button">copy</button></pre>
1564</section><section><h3><code>process.emitWarning(warning[, options])</code><span><a class="mark" href="#processemitwarningwarning-options" id="processemitwarningwarning-options">#</a></span><a aria-hidden="true" class="legacy" id="process_process_emitwarning_warning_options"></a></h3>
1565<div class="api_metadata">
1566<span>Added in: v8.0.0</span>
1567</div>
1568<ul>
1569<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>
1570<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1571<ul>
1572<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
1573for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
1574<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>
1575<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
1576function used to limit the generated stack trace. <strong>Default:</strong>
1577<code>process.emitWarning</code>.</li>
1578<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>
1579</ul>
1580</li>
1581</ul>
1582<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
1583specific process warnings. These can be listened for by adding a handler to the
1584<a href="#event-warning"><code>'warning'</code></a> event.</p>
1585
1586<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1587
1588<span class="hljs-comment">// Emit a warning with a code and additional detail.</span>
1589<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, {
1590  <span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>,
1591  <span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>,
1592});
1593<span class="hljs-comment">// Emits:</span>
1594<span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span>
1595<span class="hljs-comment">// This is some additional information</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1596
1597<span class="hljs-comment">// Emit a warning with a code and additional detail.</span>
1598<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, {
1599  <span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>,
1600  <span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>,
1601});
1602<span class="hljs-comment">// Emits:</span>
1603<span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span>
1604<span class="hljs-comment">// This is some additional information</span></code><button class="copy-button">copy</button></pre>
1605<p>In this example, an <code>Error</code> object is generated internally by
1606<code>process.emitWarning()</code> and passed through to the
1607<a href="#event-warning"><code>'warning'</code></a> handler.</p>
1608
1609<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1610
1611process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1612  <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>
1613  <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>
1614  <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>
1615  <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>
1616  <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>
1617});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1618
1619process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1620  <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>
1621  <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>
1622  <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>
1623  <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>
1624  <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>
1625});</code><button class="copy-button">copy</button></pre>
1626<p>If <code>warning</code> is passed as an <code>Error</code> object, the <code>options</code> argument is ignored.</p>
1627</section><section><h3><code>process.emitWarning(warning[, type[, code]][, ctor])</code><span><a class="mark" href="#processemitwarningwarning-type-code-ctor" id="processemitwarningwarning-type-code-ctor">#</a></span><a aria-hidden="true" class="legacy" id="process_process_emitwarning_warning_type_code_ctor"></a></h3>
1628<div class="api_metadata">
1629<span>Added in: v6.0.0</span>
1630</div>
1631<ul>
1632<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>
1633<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
1634for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
1635<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>
1636<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
1637function used to limit the generated stack trace. <strong>Default:</strong>
1638<code>process.emitWarning</code>.</li>
1639</ul>
1640<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
1641specific process warnings. These can be listened for by adding a handler to the
1642<a href="#event-warning"><code>'warning'</code></a> event.</p>
1643
1644<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1645
1646<span class="hljs-comment">// Emit a warning using a string.</span>
1647<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>);
1648<span class="hljs-comment">// Emits: (node: 56338) Warning: Something happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1649
1650<span class="hljs-comment">// Emit a warning using a string.</span>
1651<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>);
1652<span class="hljs-comment">// Emits: (node: 56338) Warning: Something happened!</span></code><button class="copy-button">copy</button></pre>
1653
1654<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1655
1656<span class="hljs-comment">// Emit a warning using a string and a type.</span>
1657<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>);
1658<span class="hljs-comment">// Emits: (node:56338) CustomWarning: Something Happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1659
1660<span class="hljs-comment">// Emit a warning using a string and a type.</span>
1661<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>);
1662<span class="hljs-comment">// Emits: (node:56338) CustomWarning: Something Happened!</span></code><button class="copy-button">copy</button></pre>
1663
1664<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1665
1666<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>);
1667<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1668
1669process.<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>);
1670<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre>
1671<p>In each of the previous examples, an <code>Error</code> object is generated internally by
1672<code>process.emitWarning()</code> and passed through to the <a href="#event-warning"><code>'warning'</code></a>
1673handler.</p>
1674
1675<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1676
1677process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1678  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);
1679  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>);
1680  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);
1681  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);
1682});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1683
1684process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
1685  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);
1686  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>);
1687  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);
1688  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);
1689});</code><button class="copy-button">copy</button></pre>
1690<p>If <code>warning</code> is passed as an <code>Error</code> object, it will be passed through to the
1691<code>'warning'</code> event handler unmodified (and the optional <code>type</code>,
1692<code>code</code> and <code>ctor</code> arguments will be ignored):</p>
1693
1694<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1695
1696<span class="hljs-comment">// Emit a warning using an Error object.</span>
1697<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>);
1698<span class="hljs-comment">// Use the Error name property to specify the type name</span>
1699myWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>;
1700myWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>;
1701
1702<span class="hljs-title function_">emitWarning</span>(myWarning);
1703<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1704
1705<span class="hljs-comment">// Emit a warning using an Error object.</span>
1706<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>);
1707<span class="hljs-comment">// Use the Error name property to specify the type name</span>
1708myWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>;
1709myWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>;
1710
1711<span class="hljs-title function_">emitWarning</span>(myWarning);
1712<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre>
1713<p>A <code>TypeError</code> is thrown if <code>warning</code> is anything other than a string or <code>Error</code>
1714object.</p>
1715<p>While process warnings use <code>Error</code> objects, the process warning
1716mechanism is <strong>not</strong> a replacement for normal error handling mechanisms.</p>
1717<p>The following additional handling is implemented if the warning <code>type</code> is
1718<code>'DeprecationWarning'</code>:</p>
1719<ul>
1720<li>If the <code>--throw-deprecation</code> command-line flag is used, the deprecation
1721warning is thrown as an exception rather than being emitted as an event.</li>
1722<li>If the <code>--no-deprecation</code> command-line flag is used, the deprecation
1723warning is suppressed.</li>
1724<li>If the <code>--trace-deprecation</code> command-line flag is used, the deprecation
1725warning is printed to <code>stderr</code> along with the full stack trace.</li>
1726</ul>
1727<h4>Avoiding duplicate warnings<span><a class="mark" href="#avoiding-duplicate-warnings" id="avoiding-duplicate-warnings">#</a></span><a aria-hidden="true" class="legacy" id="process_avoiding_duplicate_warnings"></a></h4>
1728<p>As a best practice, warnings should be emitted only once per process. To do
1729so, place the <code>emitWarning()</code> behind a boolean.</p>
1730
1731<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1732
1733<span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) {
1734  <span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) {
1735    emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>;
1736    <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>);
1737  }
1738}
1739<span class="hljs-title function_">emitMyWarning</span>();
1740<span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span>
1741<span class="hljs-title function_">emitMyWarning</span>();
1742<span class="hljs-comment">// Emits nothing</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1743
1744<span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) {
1745  <span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) {
1746    emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>;
1747    <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>);
1748  }
1749}
1750<span class="hljs-title function_">emitMyWarning</span>();
1751<span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span>
1752<span class="hljs-title function_">emitMyWarning</span>();
1753<span class="hljs-comment">// Emits nothing</span></code><button class="copy-button">copy</button></pre>
1754</section><section><h3><code>process.env</code><span><a class="mark" href="#processenv" id="processenv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_env"></a></h3>
1755<div class="api_metadata">
1756<details class="changelog"><summary>History</summary>
1757<table>
1758<tbody><tr><th>Version</th><th>Changes</th></tr>
1759<tr><td>v11.14.0</td>
1760<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>
1761<tr><td>v10.0.0</td>
1762<td><p>Implicit conversion of variable value to string is deprecated.</p></td></tr>
1763<tr><td>v0.1.27</td>
1764<td><p><span>Added in: v0.1.27</span></p></td></tr>
1765</tbody></table>
1766</details>
1767</div>
1768<ul>
1769<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
1770</ul>
1771<p>The <code>process.env</code> property returns an object containing the user environment.
1772See <a href="http://man7.org/linux/man-pages/man7/environ.7.html"><code>environ(7)</code></a>.</p>
1773<p>An example of this object looks like:</p>
1774<!-- eslint-skip -->
1775<pre><code class="language-js">{
1776  <span class="hljs-attr">TERM</span>: <span class="hljs-string">'xterm-256color'</span>,
1777  <span class="hljs-attr">SHELL</span>: <span class="hljs-string">'/usr/local/bin/bash'</span>,
1778  <span class="hljs-attr">USER</span>: <span class="hljs-string">'maciej'</span>,
1779  <span class="hljs-attr">PATH</span>: <span class="hljs-string">'~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'</span>,
1780  <span class="hljs-attr">PWD</span>: <span class="hljs-string">'/Users/maciej'</span>,
1781  <span class="hljs-attr">EDITOR</span>: <span class="hljs-string">'vim'</span>,
1782  <span class="hljs-attr">SHLVL</span>: <span class="hljs-string">'1'</span>,
1783  <span class="hljs-attr">HOME</span>: <span class="hljs-string">'/Users/maciej'</span>,
1784  <span class="hljs-attr">LOGNAME</span>: <span class="hljs-string">'maciej'</span>,
1785  <span class="hljs-attr">_</span>: <span class="hljs-string">'/usr/local/bin/node'</span>
1786}</code> <button class="copy-button">copy</button></pre>
1787<p>It is possible to modify this object, but such modifications will not be
1788reflected outside the Node.js process, or (unless explicitly requested)
1789to other <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.
1790In other words, the following example would not work:</p>
1791<pre><code class="language-console"><span class="hljs-meta prompt_">$ </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> <button class="copy-button">copy</button></pre>
1792<p>While the following will:</p>
1793
1794<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1795
1796env.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>;
1797<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">foo</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1798
1799env.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>;
1800<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">foo</span>);</code><button class="copy-button">copy</button></pre>
1801<p>Assigning a property on <code>process.env</code> will implicitly convert the value
1802to a string. <strong>This behavior is deprecated.</strong> Future versions of Node.js may
1803throw an error when the value is not a string, number, or boolean.</p>
1804
1805<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1806
1807env.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>;
1808<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
1809<span class="hljs-comment">// => 'null'</span>
1810env.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>;
1811<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
1812<span class="hljs-comment">// => 'undefined'</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1813
1814env.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>;
1815<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
1816<span class="hljs-comment">// => 'null'</span>
1817env.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>;
1818<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
1819<span class="hljs-comment">// => 'undefined'</span></code><button class="copy-button">copy</button></pre>
1820<p>Use <code>delete</code> to delete a property from <code>process.env</code>.</p>
1821
1822<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1823
1824env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
1825<span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>;
1826<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>);
1827<span class="hljs-comment">// => undefined</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1828
1829env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
1830<span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>;
1831<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>);
1832<span class="hljs-comment">// => undefined</span></code><button class="copy-button">copy</button></pre>
1833<p>On Windows operating systems, environment variables are case-insensitive.</p>
1834
1835<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1836
1837env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
1838<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
1839<span class="hljs-comment">// => 1</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1840
1841env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
1842<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
1843<span class="hljs-comment">// => 1</span></code><button class="copy-button">copy</button></pre>
1844<p>Unless explicitly specified when creating a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance,
1845each <a href="worker_threads.html#class-worker"><code>Worker</code></a> thread has its own copy of <code>process.env</code>, based on its
1846parent thread's <code>process.env</code>, or whatever was specified as the <code>env</code> option
1847to the <a href="worker_threads.html#class-worker"><code>Worker</code></a> constructor. Changes to <code>process.env</code> will not be visible
1848across <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, and only the main thread can make changes that
1849are visible to the operating system or to native add-ons. On Windows, a copy of
1850<code>process.env</code> on a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance operates in a case-sensitive manner
1851unlike the main thread.</p>
1852</section><section><h3><code>process.execArgv</code><span><a class="mark" href="#processexecargv" id="processexecargv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_execargv"></a></h3>
1853<div class="api_metadata">
1854<span>Added in: v0.7.7</span>
1855</div>
1856<ul>
1857<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
1858</ul>
1859<p>The <code>process.execArgv</code> property returns the set of Node.js-specific command-line
1860options passed when the Node.js process was launched. These options do not
1861appear in the array returned by the <a href="#processargv"><code>process.argv</code></a> property, and do not
1862include the Node.js executable, the name of the script, or any options following
1863the script name. These options are useful in order to spawn child processes with
1864the same execution environment as the parent.</p>
1865<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node --harmony script.js --version</span></code> <button class="copy-button">copy</button></pre>
1866<p>Results in <code>process.execArgv</code>:</p>
1867<!-- eslint-disable semi -->
1868<pre><code class="language-js">[<span class="hljs-string">'--harmony'</span>]</code> <button class="copy-button">copy</button></pre>
1869<p>And <code>process.argv</code>:</p>
1870<!-- eslint-disable semi -->
1871<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> <button class="copy-button">copy</button></pre>
1872<p>Refer to <a href="worker_threads.html#new-workerfilename-options"><code>Worker</code> constructor</a> for the detailed behavior of worker
1873threads with this property.</p>
1874</section><section><h3><code>process.execPath</code><span><a class="mark" href="#processexecpath" id="processexecpath">#</a></span><a aria-hidden="true" class="legacy" id="process_process_execpath"></a></h3>
1875<div class="api_metadata">
1876<span>Added in: v0.1.100</span>
1877</div>
1878<ul>
1879<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1880</ul>
1881<p>The <code>process.execPath</code> property returns the absolute pathname of the executable
1882that started the Node.js process. Symbolic links, if any, are resolved.</p>
1883<!-- eslint-disable semi -->
1884<pre><code class="language-js"><span class="hljs-string">'/usr/local/bin/node'</span></code> <button class="copy-button">copy</button></pre>
1885</section><section><h3><code>process.exit([code])</code><span><a class="mark" href="#processexitcode" id="processexitcode">#</a></span><a aria-hidden="true" class="legacy" id="process_process_exit_code"></a></h3>
1886<div class="api_metadata">
1887<span>Added in: v0.1.13</span>
1888</div>
1889<ul>
1890<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>
1891</ul>
1892<p>The <code>process.exit()</code> method instructs Node.js to terminate the process
1893synchronously with an exit status of <code>code</code>. If <code>code</code> is omitted, exit uses
1894either the 'success' code <code>0</code> or the value of <code>process.exitCode</code> if it has been
1895set. Node.js will not terminate until all the <a href="#event-exit"><code>'exit'</code></a> event listeners are
1896called.</p>
1897<p>To exit with a 'failure' code:</p>
1898
1899<pre class="with-41-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { exit } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1900
1901<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { exit } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1902
1903<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);</code><button class="copy-button">copy</button></pre>
1904<p>The shell that executed Node.js should see the exit code as <code>1</code>.</p>
1905<p>Calling <code>process.exit()</code> will force the process to exit as quickly as possible
1906even if there are still asynchronous operations pending that have not yet
1907completed fully, including I/O operations to <code>process.stdout</code> and
1908<code>process.stderr</code>.</p>
1909<p>In most situations, it is not actually necessary to call <code>process.exit()</code>
1910explicitly. The Node.js process will exit on its own <em>if there is no additional
1911work pending</em> in the event loop. The <code>process.exitCode</code> property can be set to
1912tell the process which exit code to use when the process exits gracefully.</p>
1913<p>For instance, the following example illustrates a <em>misuse</em> of the
1914<code>process.exit()</code> method that could lead to data printed to stdout being
1915truncated and lost:</p>
1916
1917<pre class="with-41-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { exit } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1918
1919<span class="hljs-comment">// This is an example of what *not* to do:</span>
1920<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
1921  <span class="hljs-title function_">printUsageToStdout</span>();
1922  <span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);
1923}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { exit } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1924
1925<span class="hljs-comment">// This is an example of what *not* to do:</span>
1926<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
1927  <span class="hljs-title function_">printUsageToStdout</span>();
1928  <span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);
1929}</code><button class="copy-button">copy</button></pre>
1930<p>The reason this is problematic is because writes to <code>process.stdout</code> in Node.js
1931are sometimes <em>asynchronous</em> and may occur over multiple ticks of the Node.js
1932event loop. Calling <code>process.exit()</code>, however, forces the process to exit
1933<em>before</em> those additional writes to <code>stdout</code> can be performed.</p>
1934<p>Rather than calling <code>process.exit()</code> directly, the code <em>should</em> set the
1935<code>process.exitCode</code> and allow the process to exit naturally by avoiding
1936scheduling any additional work for the event loop:</p>
1937
1938<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1939
1940<span class="hljs-comment">// How to properly set the exit code while letting</span>
1941<span class="hljs-comment">// the process exit gracefully.</span>
1942<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
1943  <span class="hljs-title function_">printUsageToStdout</span>();
1944  process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
1945}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1946
1947<span class="hljs-comment">// How to properly set the exit code while letting</span>
1948<span class="hljs-comment">// the process exit gracefully.</span>
1949<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
1950  <span class="hljs-title function_">printUsageToStdout</span>();
1951  process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
1952}</code><button class="copy-button">copy</button></pre>
1953<p>If it is necessary to terminate the Node.js process due to an error condition,
1954throwing an <em>uncaught</em> error and allowing the process to terminate accordingly
1955is safer than calling <code>process.exit()</code>.</p>
1956<p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, this function stops the current thread rather
1957than the current process.</p>
1958</section><section><h3><code>process.exitCode</code><span><a class="mark" href="#processexitcode_1" id="processexitcode_1">#</a></span><a aria-hidden="true" class="legacy" id="process_process_exitcode"></a></h3>
1959<div class="api_metadata">
1960<span>Added in: v0.11.8</span>
1961</div>
1962<ul>
1963<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
1964</ul>
1965<p>A number which will be the process exit code, when the process either
1966exits gracefully, or is exited via <a href="#processexitcode"><code>process.exit()</code></a> without specifying
1967a code.</p>
1968<p>Specifying a code to <a href="#processexitcode"><code>process.exit(code)</code></a> will override any
1969previous setting of <code>process.exitCode</code>.</p>
1970</section><section><h3><code>process.getActiveResourcesInfo()</code><span><a class="mark" href="#processgetactiveresourcesinfo" id="processgetactiveresourcesinfo">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getactiveresourcesinfo"></a></h3>
1971<div class="api_metadata">
1972<span>Added in: v17.3.0, v16.14.0</span>
1973</div>
1974<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
1975<ul>
1976<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
1977</ul>
1978<p>The <code>process.getActiveResourcesInfo()</code> method returns an array of strings
1979containing the types of the active resources that are currently keeping the
1980event loop alive.</p>
1981
1982<pre class="with-59-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { getActiveResourcesInfo } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
1983<span class="hljs-keyword">import</span> { <span class="hljs-built_in">setTimeout</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:timers'</span>;
1984
1985<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Before:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
1986<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>);
1987<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'After:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
1988<span class="hljs-comment">// Prints:</span>
1989<span class="hljs-comment">//   Before: [ 'CloseReq', 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span>
1990<span class="hljs-comment">//   After: [ 'CloseReq', 'TTYWrap', 'TTYWrap', 'TTYWrap', 'Timeout' ]</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { getActiveResourcesInfo } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
1991<span class="hljs-keyword">const</span> { <span class="hljs-built_in">setTimeout</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:timers'</span>);
1992
1993<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Before:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
1994<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>);
1995<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'After:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
1996<span class="hljs-comment">// Prints:</span>
1997<span class="hljs-comment">//   Before: [ 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span>
1998<span class="hljs-comment">//   After: [ 'TTYWrap', 'TTYWrap', 'TTYWrap', 'Timeout' ]</span></code><button class="copy-button">copy</button></pre>
1999</section><section><h3><code>process.getegid()</code><span><a class="mark" href="#processgetegid" id="processgetegid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getegid"></a></h3>
2000<div class="api_metadata">
2001<span>Added in: v2.0.0</span>
2002</div>
2003<p>The <code>process.getegid()</code> method returns the numerical effective group identity
2004of the Node.js process. (See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html"><code>getegid(2)</code></a>.)</p>
2005
2006<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2007
2008<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) {
2009  <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>);
2010}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2011
2012<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) {
2013  <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>);
2014}</code><button class="copy-button">copy</button></pre>
2015<p>This function is only available on POSIX platforms (i.e. not Windows or
2016Android).</p>
2017</section><section><h3><code>process.geteuid()</code><span><a class="mark" href="#processgeteuid" id="processgeteuid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_geteuid"></a></h3>
2018<div class="api_metadata">
2019<span>Added in: v2.0.0</span>
2020</div>
2021<ul>
2022<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2023</ul>
2024<p>The <code>process.geteuid()</code> method returns the numerical effective user identity of
2025the process. (See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html"><code>geteuid(2)</code></a>.)</p>
2026
2027<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2028
2029<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) {
2030  <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>);
2031}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2032
2033<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) {
2034  <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>);
2035}</code><button class="copy-button">copy</button></pre>
2036<p>This function is only available on POSIX platforms (i.e. not Windows or
2037Android).</p>
2038</section><section><h3><code>process.getgid()</code><span><a class="mark" href="#processgetgid" id="processgetgid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getgid"></a></h3>
2039<div class="api_metadata">
2040<span>Added in: v0.1.31</span>
2041</div>
2042<ul>
2043<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2044</ul>
2045<p>The <code>process.getgid()</code> method returns the numerical group identity of the
2046process. (See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html"><code>getgid(2)</code></a>.)</p>
2047
2048<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2049
2050<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) {
2051  <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>);
2052}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2053
2054<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) {
2055  <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>);
2056}</code><button class="copy-button">copy</button></pre>
2057<p>This function is only available on POSIX platforms (i.e. not Windows or
2058Android).</p>
2059</section><section><h3><code>process.getgroups()</code><span><a class="mark" href="#processgetgroups" id="processgetgroups">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getgroups"></a></h3>
2060<div class="api_metadata">
2061<span>Added in: v0.9.4</span>
2062</div>
2063<ul>
2064<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
2065</ul>
2066<p>The <code>process.getgroups()</code> method returns an array with the supplementary group
2067IDs. POSIX leaves it unspecified if the effective group ID is included but
2068Node.js ensures it always is.</p>
2069
2070<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2071
2072<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) {
2073  <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>
2074}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2075
2076<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) {
2077  <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>
2078}</code><button class="copy-button">copy</button></pre>
2079<p>This function is only available on POSIX platforms (i.e. not Windows or
2080Android).</p>
2081</section><section><h3><code>process.getuid()</code><span><a class="mark" href="#processgetuid" id="processgetuid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getuid"></a></h3>
2082<div class="api_metadata">
2083<span>Added in: v0.1.28</span>
2084</div>
2085<ul>
2086<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
2087</ul>
2088<p>The <code>process.getuid()</code> method returns the numeric user identity of the process.
2089(See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html"><code>getuid(2)</code></a>.)</p>
2090
2091<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2092
2093<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) {
2094  <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>);
2095}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2096
2097<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) {
2098  <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>);
2099}</code><button class="copy-button">copy</button></pre>
2100<p>This function is only available on POSIX platforms (i.e. not Windows or
2101Android).</p>
2102</section><section><h3><code>process.hasUncaughtExceptionCaptureCallback()</code><span><a class="mark" href="#processhasuncaughtexceptioncapturecallback" id="processhasuncaughtexceptioncapturecallback">#</a></span><a aria-hidden="true" class="legacy" id="process_process_hasuncaughtexceptioncapturecallback"></a></h3>
2103<div class="api_metadata">
2104<span>Added in: v9.3.0</span>
2105</div>
2106<ul>
2107<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2108</ul>
2109<p>Indicates whether a callback has been set using
2110<a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a>.</p>
2111</section><section><h3><code>process.hrtime([time])</code><span><a class="mark" href="#processhrtimetime" id="processhrtimetime">#</a></span><a aria-hidden="true" class="legacy" id="process_process_hrtime_time"></a></h3>
2112<div class="api_metadata">
2113<span>Added in: v0.7.6</span>
2114</div>
2115<p></p><div class="api_stability api_stability_3"><a href="documentation.html#stability-index">Stability: 3</a> - Legacy. Use <a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a> instead.</div><p></p>
2116<ul>
2117<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>
2118<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
2119</ul>
2120<p>This is the legacy version of <a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a>
2121before <code>bigint</code> was introduced in JavaScript.</p>
2122<p>The <code>process.hrtime()</code> method returns the current high-resolution real time
2123in a <code>[seconds, nanoseconds]</code> tuple <code>Array</code>, where <code>nanoseconds</code> is the
2124remaining part of the real time that can't be represented in second precision.</p>
2125<p><code>time</code> is an optional parameter that must be the result of a previous
2126<code>process.hrtime()</code> call to diff with the current time. If the parameter
2127passed in is not a tuple <code>Array</code>, a <code>TypeError</code> will be thrown. Passing in a
2128user-defined array instead of the result of a previous call to
2129<code>process.hrtime()</code> will lead to undefined behavior.</p>
2130<p>These times are relative to an arbitrary time in the
2131past, and not related to the time of day and therefore not subject to clock
2132drift. The primary use is for measuring performance between intervals:</p>
2133
2134<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { hrtime } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2135
2136<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>;
2137<span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>();
2138<span class="hljs-comment">// [ 1800216, 25 ]</span>
2139
2140<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
2141  <span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time);
2142  <span class="hljs-comment">// [ 1, 552 ]</span>
2143
2144  <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>);
2145  <span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span>
2146}, <span class="hljs-number">1000</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { hrtime } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2147
2148<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>;
2149<span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>();
2150<span class="hljs-comment">// [ 1800216, 25 ]</span>
2151
2152<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
2153  <span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time);
2154  <span class="hljs-comment">// [ 1, 552 ]</span>
2155
2156  <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>);
2157  <span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span>
2158}, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre>
2159</section><section><h3><code>process.hrtime.bigint()</code><span><a class="mark" href="#processhrtimebigint" id="processhrtimebigint">#</a></span><a aria-hidden="true" class="legacy" id="process_process_hrtime_bigint"></a></h3>
2160<div class="api_metadata">
2161<span>Added in: v10.7.0</span>
2162</div>
2163<ul>
2164<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
2165</ul>
2166<p>The <code>bigint</code> version of the <a href="#processhrtimetime"><code>process.hrtime()</code></a> method returning the
2167current high-resolution real time in nanoseconds as a <code>bigint</code>.</p>
2168<p>Unlike <a href="#processhrtimetime"><code>process.hrtime()</code></a>, it does not support an additional <code>time</code>
2169argument since the difference can just be computed directly
2170by subtraction of the two <code>bigint</code>s.</p>
2171
2172<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { hrtime } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2173
2174<span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>();
2175<span class="hljs-comment">// 191051479007711n</span>
2176
2177<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
2178  <span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>();
2179  <span class="hljs-comment">// 191052633396993n</span>
2180
2181  <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>);
2182  <span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span>
2183}, <span class="hljs-number">1000</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { hrtime } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2184
2185<span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>();
2186<span class="hljs-comment">// 191051479007711n</span>
2187
2188<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
2189  <span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>();
2190  <span class="hljs-comment">// 191052633396993n</span>
2191
2192  <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>);
2193  <span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span>
2194}, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre>
2195</section><section><h3><code>process.initgroups(user, extraGroup)</code><span><a class="mark" href="#processinitgroupsuser-extragroup" id="processinitgroupsuser-extragroup">#</a></span><a aria-hidden="true" class="legacy" id="process_process_initgroups_user_extragroup"></a></h3>
2196<div class="api_metadata">
2197<span>Added in: v0.9.4</span>
2198</div>
2199<ul>
2200<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>
2201<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>
2202</ul>
2203<p>The <code>process.initgroups()</code> method reads the <code>/etc/group</code> file and initializes
2204the group access list, using all groups of which the user is a member. This is
2205a privileged operation that requires that the Node.js process either have <code>root</code>
2206access or the <code>CAP_SETGID</code> capability.</p>
2207<p>Use care when dropping privileges:</p>
2208
2209<pre class="with-66-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { getgroups, initgroups, setgid } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2210
2211<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 0 ]</span>
2212<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>
2213<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 27, 30, 46, 1000, 0 ]</span>
2214<span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>);                     <span class="hljs-comment">// drop root gid</span>
2215<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 27, 30, 46, 1000 ]</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { getgroups, initgroups, setgid } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2216
2217<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 0 ]</span>
2218<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>
2219<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 27, 30, 46, 1000, 0 ]</span>
2220<span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>);                     <span class="hljs-comment">// drop root gid</span>
2221<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>());         <span class="hljs-comment">// [ 27, 30, 46, 1000 ]</span></code><button class="copy-button">copy</button></pre>
2222<p>This function is only available on POSIX platforms (i.e. not Windows or
2223Android).
2224This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
2225</section><section><h3><code>process.kill(pid[, signal])</code><span><a class="mark" href="#processkillpid-signal" id="processkillpid-signal">#</a></span><a aria-hidden="true" class="legacy" id="process_process_kill_pid_signal"></a></h3>
2226<div class="api_metadata">
2227<span>Added in: v0.0.6</span>
2228</div>
2229<ul>
2230<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>
2231<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.
2232<strong>Default:</strong> <code>'SIGTERM'</code>.</li>
2233</ul>
2234<p>The <code>process.kill()</code> method sends the <code>signal</code> to the process identified by
2235<code>pid</code>.</p>
2236<p>Signal names are strings such as <code>'SIGINT'</code> or <code>'SIGHUP'</code>. See <a href="#signal-events">Signal Events</a>
2237and <a href="http://man7.org/linux/man-pages/man2/kill.2.html"><code>kill(2)</code></a> for more information.</p>
2238<p>This method will throw an error if the target <code>pid</code> does not exist. As a special
2239case, a signal of <code>0</code> can be used to test for the existence of a process.
2240Windows platforms will throw an error if the <code>pid</code> is used to kill a process
2241group.</p>
2242<p>Even though the name of this function is <code>process.kill()</code>, it is really just a
2243signal sender, like the <code>kill</code> system call. The signal sent may do something
2244other than kill the target process.</p>
2245
2246<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process, { kill } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2247
2248process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> {
2249  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>);
2250});
2251
2252<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
2253  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>);
2254  process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
2255}, <span class="hljs-number">100</span>);
2256
2257<span class="hljs-title function_">kill</span>(process.<span class="hljs-property">pid</span>, <span class="hljs-string">'SIGHUP'</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2258
2259process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> {
2260  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>);
2261});
2262
2263<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
2264  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>);
2265  process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
2266}, <span class="hljs-number">100</span>);
2267
2268process.<span class="hljs-title function_">kill</span>(process.<span class="hljs-property">pid</span>, <span class="hljs-string">'SIGHUP'</span>);</code><button class="copy-button">copy</button></pre>
2269<p>When <code>SIGUSR1</code> is received by a Node.js process, Node.js will start the
2270debugger. See <a href="#signal-events">Signal Events</a>.</p>
2271</section><section><h3><code>process.mainModule</code><span><a class="mark" href="#processmainmodule" id="processmainmodule">#</a></span><a aria-hidden="true" class="legacy" id="process_process_mainmodule"></a></h3>
2272<div class="api_metadata">
2273<span>Added in: v0.1.17</span><span>Deprecated since: v14.0.0</span>
2274</div>
2275<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="modules.html#accessing-the-main-module"><code>require.main</code></a> instead.</div><p></p>
2276<ul>
2277<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2278</ul>
2279<p>The <code>process.mainModule</code> property provides an alternative way of retrieving
2280<a href="modules.html#accessing-the-main-module"><code>require.main</code></a>. The difference is that if the main module changes at
2281runtime, <a href="modules.html#accessing-the-main-module"><code>require.main</code></a> may still refer to the original main module in
2282modules that were required before the change occurred. Generally, it's
2283safe to assume that the two refer to the same module.</p>
2284<p>As with <a href="modules.html#accessing-the-main-module"><code>require.main</code></a>, <code>process.mainModule</code> will be <code>undefined</code> if there
2285is no entry script.</p>
2286</section><section><h3><code>process.memoryUsage()</code><span><a class="mark" href="#processmemoryusage" id="processmemoryusage">#</a></span><a aria-hidden="true" class="legacy" id="process_process_memoryusage"></a></h3>
2287<div class="api_metadata">
2288<details class="changelog"><summary>History</summary>
2289<table>
2290<tbody><tr><th>Version</th><th>Changes</th></tr>
2291<tr><td>v13.9.0, v12.17.0</td>
2292<td><p>Added <code>arrayBuffers</code> to the returned object.</p></td></tr>
2293<tr><td>v7.2.0</td>
2294<td><p>Added <code>external</code> to the returned object.</p></td></tr>
2295<tr><td>v0.1.16</td>
2296<td><p><span>Added in: v0.1.16</span></p></td></tr>
2297</tbody></table>
2298</details>
2299</div>
2300<ul>
2301<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
2302<ul>
2303<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>
2304<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>
2305<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>
2306<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>
2307<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>
2308</ul>
2309</li>
2310</ul>
2311<p>Returns an object describing the memory usage of the Node.js process measured in
2312bytes.</p>
2313
2314<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { memoryUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2315
2316<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>());
2317<span class="hljs-comment">// Prints:</span>
2318<span class="hljs-comment">// {</span>
2319<span class="hljs-comment">//  rss: 4935680,</span>
2320<span class="hljs-comment">//  heapTotal: 1826816,</span>
2321<span class="hljs-comment">//  heapUsed: 650472,</span>
2322<span class="hljs-comment">//  external: 49879,</span>
2323<span class="hljs-comment">//  arrayBuffers: 9386</span>
2324<span class="hljs-comment">// }</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { memoryUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2325
2326<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>());
2327<span class="hljs-comment">// Prints:</span>
2328<span class="hljs-comment">// {</span>
2329<span class="hljs-comment">//  rss: 4935680,</span>
2330<span class="hljs-comment">//  heapTotal: 1826816,</span>
2331<span class="hljs-comment">//  heapUsed: 650472,</span>
2332<span class="hljs-comment">//  external: 49879,</span>
2333<span class="hljs-comment">//  arrayBuffers: 9386</span>
2334<span class="hljs-comment">// }</span></code><button class="copy-button">copy</button></pre>
2335<ul>
2336<li><code>heapTotal</code> and <code>heapUsed</code> refer to V8's memory usage.</li>
2337<li><code>external</code> refers to the memory usage of C++ objects bound to JavaScript
2338objects managed by V8.</li>
2339<li><code>rss</code>, Resident Set Size, is the amount of space occupied in the main
2340memory device (that is a subset of the total allocated memory) for the
2341process, including all C++ and JavaScript objects and code.</li>
2342<li><code>arrayBuffers</code> refers to memory allocated for <code>ArrayBuffer</code>s and
2343<code>SharedArrayBuffer</code>s, including all Node.js <a href="buffer.html"><code>Buffer</code></a>s.
2344This is also included in the <code>external</code> value. When Node.js is used as an
2345embedded library, this value may be <code>0</code> because allocations for <code>ArrayBuffer</code>s
2346may not be tracked in that case.</li>
2347</ul>
2348<p>When using <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, <code>rss</code> will be a value that is valid for the
2349entire process, while the other fields will only refer to the current thread.</p>
2350<p>The <code>process.memoryUsage()</code> method iterates over each page to gather
2351information about memory usage which might be slow depending on the
2352program memory allocations.</p>
2353</section><section><h3><code>process.memoryUsage.rss()</code><span><a class="mark" href="#processmemoryusagerss" id="processmemoryusagerss">#</a></span><a aria-hidden="true" class="legacy" id="process_process_memoryusage_rss"></a></h3>
2354<div class="api_metadata">
2355<span>Added in: v15.6.0, v14.18.0</span>
2356</div>
2357<ul>
2358<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
2359</ul>
2360<p>The <code>process.memoryUsage.rss()</code> method returns an integer representing the
2361Resident Set Size (RSS) in bytes.</p>
2362<p>The Resident Set Size, is the amount of space occupied in the main
2363memory device (that is a subset of the total allocated memory) for the
2364process, including all C++ and JavaScript objects and code.</p>
2365<p>This is the same value as the <code>rss</code> property provided by <code>process.memoryUsage()</code>
2366but <code>process.memoryUsage.rss()</code> is faster.</p>
2367
2368<pre class="with-48-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { memoryUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2369
2370<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>());
2371<span class="hljs-comment">// 35655680</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { memoryUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2372
2373<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>());
2374<span class="hljs-comment">// 35655680</span></code><button class="copy-button">copy</button></pre>
2375</section><section><h3><code>process.nextTick(callback[, ...args])</code><span><a class="mark" href="#processnexttickcallback-args" id="processnexttickcallback-args">#</a></span><a aria-hidden="true" class="legacy" id="process_process_nexttick_callback_args"></a></h3>
2376<div class="api_metadata">
2377<details class="changelog"><summary>History</summary>
2378<table>
2379<tbody><tr><th>Version</th><th>Changes</th></tr>
2380<tr><td>v18.0.0</td>
2381<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
2382<tr><td>v1.8.1</td>
2383<td><p>Additional arguments after <code>callback</code> are now supported.</p></td></tr>
2384<tr><td>v0.1.26</td>
2385<td><p><span>Added in: v0.1.26</span></p></td></tr>
2386</tbody></table>
2387</details>
2388</div>
2389<ul>
2390<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>
2391<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>
2392</ul>
2393<p><code>process.nextTick()</code> adds <code>callback</code> to the "next tick queue". This queue is
2394fully drained after the current operation on the JavaScript stack runs to
2395completion and before the event loop is allowed to continue. It's possible to
2396create an infinite loop if one were to recursively call <code>process.nextTick()</code>.
2397See the <a href="https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick">Event Loop</a> guide for more background.</p>
2398
2399<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2400
2401<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
2402<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
2403  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick callback'</span>);
2404});
2405<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
2406<span class="hljs-comment">// Output:</span>
2407<span class="hljs-comment">// start</span>
2408<span class="hljs-comment">// scheduled</span>
2409<span class="hljs-comment">// nextTick callback</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2410
2411<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
2412<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
2413  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick callback'</span>);
2414});
2415<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
2416<span class="hljs-comment">// Output:</span>
2417<span class="hljs-comment">// start</span>
2418<span class="hljs-comment">// scheduled</span>
2419<span class="hljs-comment">// nextTick callback</span></code><button class="copy-button">copy</button></pre>
2420<p>This is important when developing APIs in order to give users the opportunity
2421to assign event handlers <em>after</em> an object has been constructed but before any
2422I/O has occurred:</p>
2423
2424<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2425
2426<span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) {
2427  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options);
2428
2429  <span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
2430    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>();
2431  });
2432}
2433
2434<span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>();
2435thing.<span class="hljs-title function_">getReadyForStuff</span>();
2436
2437<span class="hljs-comment">// thing.startDoingStuff() gets called now, not before.</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2438
2439<span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) {
2440  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options);
2441
2442  <span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
2443    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>();
2444  });
2445}
2446
2447<span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>();
2448thing.<span class="hljs-title function_">getReadyForStuff</span>();
2449
2450<span class="hljs-comment">// thing.startDoingStuff() gets called now, not before.</span></code><button class="copy-button">copy</button></pre>
2451<p>It is very important for APIs to be either 100% synchronous or 100%
2452asynchronous. Consider this example:</p>
2453<pre><code class="language-js"><span class="hljs-comment">// WARNING!  DO NOT USE!  BAD UNSAFE HAZARD!</span>
2454<span class="hljs-keyword">function</span> <span class="hljs-title function_">maybeSync</span>(<span class="hljs-params">arg, cb</span>) {
2455  <span class="hljs-keyword">if</span> (arg) {
2456    <span class="hljs-title function_">cb</span>();
2457    <span class="hljs-keyword">return</span>;
2458  }
2459
2460  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
2461}</code> <button class="copy-button">copy</button></pre>
2462<p>This API is hazardous because in the following case:</p>
2463<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>;
2464
2465<span class="hljs-title function_">maybeSync</span>(maybeTrue, <span class="hljs-function">() =></span> {
2466  <span class="hljs-title function_">foo</span>();
2467});
2468
2469<span class="hljs-title function_">bar</span>();</code> <button class="copy-button">copy</button></pre>
2470<p>It is not clear whether <code>foo()</code> or <code>bar()</code> will be called first.</p>
2471<p>The following approach is much better:</p>
2472
2473<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2474
2475<span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) {
2476  <span class="hljs-keyword">if</span> (arg) {
2477    <span class="hljs-title function_">nextTick</span>(cb);
2478    <span class="hljs-keyword">return</span>;
2479  }
2480
2481  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
2482}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2483
2484<span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) {
2485  <span class="hljs-keyword">if</span> (arg) {
2486    <span class="hljs-title function_">nextTick</span>(cb);
2487    <span class="hljs-keyword">return</span>;
2488  }
2489
2490  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
2491}</code><button class="copy-button">copy</button></pre>
2492<h4>When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code><span><a class="mark" href="#when-to-use-queuemicrotask-vs-processnexttick" id="when-to-use-queuemicrotask-vs-processnexttick">#</a></span><a aria-hidden="true" class="legacy" id="process_when_to_use_queuemicrotask_vs_process_nexttick"></a></h4>
2493<p>The <a href="globals.html#queuemicrotaskcallback"><code>queueMicrotask()</code></a> API is an alternative to <code>process.nextTick()</code> that
2494also defers execution of a function using the same microtask queue used to
2495execute the then, catch, and finally handlers of resolved promises. Within
2496Node.js, every time the "next tick queue" is drained, the microtask queue
2497is drained immediately after.</p>
2498
2499<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2500
2501<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>));
2502<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>));
2503<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>));
2504<span class="hljs-comment">// Output:</span>
2505<span class="hljs-comment">// 1</span>
2506<span class="hljs-comment">// 2</span>
2507<span class="hljs-comment">// 3</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2508
2509<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>));
2510<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>));
2511<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>));
2512<span class="hljs-comment">// Output:</span>
2513<span class="hljs-comment">// 1</span>
2514<span class="hljs-comment">// 2</span>
2515<span class="hljs-comment">// 3</span></code><button class="copy-button">copy</button></pre>
2516<p>For <em>most</em> userland use cases, the <code>queueMicrotask()</code> API provides a portable
2517and reliable mechanism for deferring execution that works across multiple
2518JavaScript platform environments and should be favored over <code>process.nextTick()</code>.
2519In simple scenarios, <code>queueMicrotask()</code> can be a drop-in replacement for
2520<code>process.nextTick()</code>.</p>
2521<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>);
2522<span class="hljs-title function_">queueMicrotask</span>(<span class="hljs-function">() =></span> {
2523  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask callback'</span>);
2524});
2525<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
2526<span class="hljs-comment">// Output:</span>
2527<span class="hljs-comment">// start</span>
2528<span class="hljs-comment">// scheduled</span>
2529<span class="hljs-comment">// microtask callback</span></code> <button class="copy-button">copy</button></pre>
2530<p>One note-worthy difference between the two APIs is that <code>process.nextTick()</code>
2531allows specifying additional values that will be passed as arguments to the
2532deferred function when it is called. Achieving the same result with
2533<code>queueMicrotask()</code> requires using either a closure or a bound function:</p>
2534<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>) {
2535  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask'</span>, a + b);
2536}
2537
2538<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
2539<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>));
2540<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
2541<span class="hljs-comment">// Output:</span>
2542<span class="hljs-comment">// start</span>
2543<span class="hljs-comment">// scheduled</span>
2544<span class="hljs-comment">// microtask 3</span></code> <button class="copy-button">copy</button></pre>
2545<p>There are minor differences in the way errors raised from within the next tick
2546queue and microtask queue are handled. Errors thrown within a queued microtask
2547callback should be handled within the queued callback when possible. If they are
2548not, the <code>process.on('uncaughtException')</code> event handler can be used to capture
2549and handle the errors.</p>
2550<p>When in doubt, unless the specific capabilities of <code>process.nextTick()</code> are
2551needed, use <code>queueMicrotask()</code>.</p>
2552</section><section><h3><code>process.noDeprecation</code><span><a class="mark" href="#processnodeprecation" id="processnodeprecation">#</a></span><a aria-hidden="true" class="legacy" id="process_process_nodeprecation"></a></h3>
2553<div class="api_metadata">
2554<span>Added in: v0.8.0</span>
2555</div>
2556<ul>
2557<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2558</ul>
2559<p>The <code>process.noDeprecation</code> property indicates whether the <code>--no-deprecation</code>
2560flag is set on the current Node.js process. See the documentation for
2561the <a href="#event-warning"><code>'warning'</code> event</a> and the
2562<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this
2563flag's behavior.</p>
2564</section><section><h3><code>process.pid</code><span><a class="mark" href="#processpid" id="processpid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_pid"></a></h3>
2565<div class="api_metadata">
2566<span>Added in: v0.1.15</span>
2567</div>
2568<ul>
2569<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
2570</ul>
2571<p>The <code>process.pid</code> property returns the PID of the process.</p>
2572
2573<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { pid } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2574
2575<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">${pid}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { pid } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2576
2577<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">${pid}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2578</section><section><h3><code>process.platform</code><span><a class="mark" href="#processplatform" id="processplatform">#</a></span><a aria-hidden="true" class="legacy" id="process_process_platform"></a></h3>
2579<div class="api_metadata">
2580<span>Added in: v0.1.16</span>
2581</div>
2582<ul>
2583<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
2584</ul>
2585<p>The <code>process.platform</code> property returns a string identifying the operating
2586system platform for which the Node.js binary was compiled.</p>
2587<p>Currently possible values are:</p>
2588<ul>
2589<li><code>'aix'</code></li>
2590<li><code>'darwin'</code></li>
2591<li><code>'freebsd'</code></li>
2592<li><code>'linux'</code></li>
2593<li><code>'openbsd'</code></li>
2594<li><code>'sunos'</code></li>
2595<li><code>'win32'</code></li>
2596</ul>
2597
2598<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { platform } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2599
2600<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">${platform}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { platform } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2601
2602<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">${platform}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2603<p>The value <code>'android'</code> may also be returned if the Node.js is built on the
2604Android operating system. However, Android support in Node.js
2605<a href="https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os">is experimental</a>.</p>
2606</section><section><h3><code>process.ppid</code><span><a class="mark" href="#processppid" id="processppid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_ppid"></a></h3>
2607<div class="api_metadata">
2608<span>Added in: v9.2.0, v8.10.0, v6.13.0</span>
2609</div>
2610<ul>
2611<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
2612</ul>
2613<p>The <code>process.ppid</code> property returns the PID of the parent of the
2614current process.</p>
2615
2616<pre class="with-41-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { ppid } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2617
2618<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">${ppid}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { ppid } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2619
2620<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">${ppid}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2621</section><section><h3><code>process.release</code><span><a class="mark" href="#processrelease" id="processrelease">#</a></span><a aria-hidden="true" class="legacy" id="process_process_release"></a></h3>
2622<div class="api_metadata">
2623<details class="changelog"><summary>History</summary>
2624<table>
2625<tbody><tr><th>Version</th><th>Changes</th></tr>
2626<tr><td>v4.2.0</td>
2627<td><p>The <code>lts</code> property is now supported.</p></td></tr>
2628<tr><td>v3.0.0</td>
2629<td><p><span>Added in: v3.0.0</span></p></td></tr>
2630</tbody></table>
2631</details>
2632</div>
2633<ul>
2634<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2635</ul>
2636<p>The <code>process.release</code> property returns an <code>Object</code> containing metadata related
2637to the current release, including URLs for the source tarball and headers-only
2638tarball.</p>
2639<p><code>process.release</code> contains the following properties:</p>
2640<ul>
2641<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>
2642<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
2643the source code of the current release.</li>
2644<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
2645only the source header files for the current release. This file is
2646significantly smaller than the full source file and can be used for compiling
2647Node.js native add-ons.</li>
2648<li><code>libUrl</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#Undefined_type" class="type">&#x3C;undefined></a> an absolute URL pointing to a <em><code>node.lib</code></em> file
2649matching the architecture and version of the current release. This file is
2650used for compiling Node.js native add-ons. <em>This property is only present on
2651Windows builds of Node.js and will be missing on all other platforms.</em></li>
2652<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 href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type">&#x3C;undefined></a> a string label identifying the <a href="https://github.com/nodejs/Release">LTS</a> label for this
2653release. This property only exists for LTS releases and is <code>undefined</code> for all
2654other release types, including <em>Current</em> releases. Valid values include the
2655LTS Release code names (including those that are no longer supported).
2656<ul>
2657<li><code>'Fermium'</code> for the 14.x LTS line beginning with 14.15.0.</li>
2658<li><code>'Gallium'</code> for the 16.x LTS line beginning with 16.13.0.</li>
2659<li><code>'Hydrogen'</code> for the 18.x LTS line beginning with 18.12.0.
2660For 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>
2661</ul>
2662</li>
2663</ul>
2664<!-- eslint-skip -->
2665<pre><code class="language-js">{
2666  <span class="hljs-attr">name</span>: <span class="hljs-string">'node'</span>,
2667  <span class="hljs-attr">lts</span>: <span class="hljs-string">'Hydrogen'</span>,
2668  <span class="hljs-attr">sourceUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/node-v18.12.0.tar.gz'</span>,
2669  <span class="hljs-attr">headersUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/node-v18.12.0-headers.tar.gz'</span>,
2670  <span class="hljs-attr">libUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/win-x64/node.lib'</span>
2671}</code> <button class="copy-button">copy</button></pre>
2672<p>In custom builds from non-release versions of the source tree, only the
2673<code>name</code> property may be present. The additional properties should not be
2674relied upon to exist.</p>
2675</section><section><h3><code>process.report</code><span><a class="mark" href="#processreport" id="processreport">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report"></a></h3>
2676<div class="api_metadata">
2677<details class="changelog"><summary>History</summary>
2678<table>
2679<tbody><tr><th>Version</th><th>Changes</th></tr>
2680<tr><td>v13.12.0, v12.17.0</td>
2681<td><p>This API is no longer experimental.</p></td></tr>
2682<tr><td>v11.8.0</td>
2683<td><p><span>Added in: v11.8.0</span></p></td></tr>
2684</tbody></table>
2685</details>
2686</div>
2687<ul>
2688<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2689</ul>
2690<p><code>process.report</code> is an object whose methods are used to generate diagnostic
2691reports for the current process. Additional documentation is available in the
2692<a href="report.html">report documentation</a>.</p>
2693<h4><code>process.report.compact</code><span><a class="mark" href="#processreportcompact" id="processreportcompact">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_compact"></a></h4>
2694<div class="api_metadata">
2695<span>Added in: v13.12.0, v12.17.0</span>
2696</div>
2697<ul>
2698<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2699</ul>
2700<p>Write reports in a compact format, single-line JSON, more easily consumable
2701by log processing systems than the default multi-line format designed for
2702human consumption.</p>
2703
2704<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2705
2706<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">${report.compact}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2707
2708<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">${report.compact}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2709<h4><code>process.report.directory</code><span><a class="mark" href="#processreportdirectory" id="processreportdirectory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_directory"></a></h4>
2710<div class="api_metadata">
2711<details class="changelog"><summary>History</summary>
2712<table>
2713<tbody><tr><th>Version</th><th>Changes</th></tr>
2714<tr><td>v13.12.0, v12.17.0</td>
2715<td><p>This API is no longer experimental.</p></td></tr>
2716<tr><td>v11.12.0</td>
2717<td><p><span>Added in: v11.12.0</span></p></td></tr>
2718</tbody></table>
2719</details>
2720</div>
2721<ul>
2722<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
2723</ul>
2724<p>Directory where the report is written. The default value is the empty string,
2725indicating that reports are written to the current working directory of the
2726Node.js process.</p>
2727
2728<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2729
2730<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">${report.directory}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2731
2732<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">${report.directory}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2733<h4><code>process.report.filename</code><span><a class="mark" href="#processreportfilename" id="processreportfilename">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_filename"></a></h4>
2734<div class="api_metadata">
2735<details class="changelog"><summary>History</summary>
2736<table>
2737<tbody><tr><th>Version</th><th>Changes</th></tr>
2738<tr><td>v13.12.0, v12.17.0</td>
2739<td><p>This API is no longer experimental.</p></td></tr>
2740<tr><td>v11.12.0</td>
2741<td><p><span>Added in: v11.12.0</span></p></td></tr>
2742</tbody></table>
2743</details>
2744</div>
2745<ul>
2746<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
2747</ul>
2748<p>Filename where the report is written. If set to the empty string, the output
2749filename will be comprised of a timestamp, PID, and sequence number. The default
2750value is the empty string.</p>
2751<p>If the value of <code>process.report.filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>,
2752the report is written to the stdout or stderr of the process respectively.</p>
2753
2754<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2755
2756<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">${report.filename}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2757
2758<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">${report.filename}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2759<h4><code>process.report.getReport([err])</code><span><a class="mark" href="#processreportgetreporterr" id="processreportgetreporterr">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_getreport_err"></a></h4>
2760<div class="api_metadata">
2761<details class="changelog"><summary>History</summary>
2762<table>
2763<tbody><tr><th>Version</th><th>Changes</th></tr>
2764<tr><td>v13.12.0, v12.17.0</td>
2765<td><p>This API is no longer experimental.</p></td></tr>
2766<tr><td>v11.8.0</td>
2767<td><p><span>Added in: v11.8.0</span></p></td></tr>
2768</tbody></table>
2769</details>
2770</div>
2771<ul>
2772<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>
2773<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
2774</ul>
2775<p>Returns a JavaScript Object representation of a diagnostic report for the
2776running process. The report's JavaScript stack trace is taken from <code>err</code>, if
2777present.</p>
2778
2779<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2780<span class="hljs-keyword">import</span> util <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
2781
2782<span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>();
2783<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>);
2784
2785<span class="hljs-comment">// Similar to process.report.writeReport()</span>
2786<span class="hljs-keyword">import</span> fs <span class="hljs-keyword">from</span> <span class="hljs-string">'node:fs'</span>;
2787fs.<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><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2788<span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
2789
2790<span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>();
2791<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>);
2792
2793<span class="hljs-comment">// Similar to process.report.writeReport()</span>
2794<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
2795fs.<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><button class="copy-button">copy</button></pre>
2796<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
2797<h4><code>process.report.reportOnFatalError</code><span><a class="mark" href="#processreportreportonfatalerror" id="processreportreportonfatalerror">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_reportonfatalerror"></a></h4>
2798<div class="api_metadata">
2799<details class="changelog"><summary>History</summary>
2800<table>
2801<tbody><tr><th>Version</th><th>Changes</th></tr>
2802<tr><td>v15.0.0, v14.17.0</td>
2803<td><p>This API is no longer experimental.</p></td></tr>
2804<tr><td>v11.12.0</td>
2805<td><p><span>Added in: v11.12.0</span></p></td></tr>
2806</tbody></table>
2807</details>
2808</div>
2809<ul>
2810<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2811</ul>
2812<p>If <code>true</code>, a diagnostic report is generated on fatal errors, such as out of
2813memory errors or failed C++ assertions.</p>
2814
2815<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2816
2817<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">${report.reportOnFatalError}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2818
2819<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">${report.reportOnFatalError}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2820<h4><code>process.report.reportOnSignal</code><span><a class="mark" href="#processreportreportonsignal" id="processreportreportonsignal">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_reportonsignal"></a></h4>
2821<div class="api_metadata">
2822<details class="changelog"><summary>History</summary>
2823<table>
2824<tbody><tr><th>Version</th><th>Changes</th></tr>
2825<tr><td>v13.12.0, v12.17.0</td>
2826<td><p>This API is no longer experimental.</p></td></tr>
2827<tr><td>v11.12.0</td>
2828<td><p><span>Added in: v11.12.0</span></p></td></tr>
2829</tbody></table>
2830</details>
2831</div>
2832<ul>
2833<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2834</ul>
2835<p>If <code>true</code>, a diagnostic report is generated when the process receives the
2836signal specified by <code>process.report.signal</code>.</p>
2837
2838<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2839
2840<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">${report.reportOnSignal}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2841
2842<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">${report.reportOnSignal}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2843<h4><code>process.report.reportOnUncaughtException</code><span><a class="mark" href="#processreportreportonuncaughtexception" id="processreportreportonuncaughtexception">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_reportonuncaughtexception"></a></h4>
2844<div class="api_metadata">
2845<details class="changelog"><summary>History</summary>
2846<table>
2847<tbody><tr><th>Version</th><th>Changes</th></tr>
2848<tr><td>v13.12.0, v12.17.0</td>
2849<td><p>This API is no longer experimental.</p></td></tr>
2850<tr><td>v11.12.0</td>
2851<td><p><span>Added in: v11.12.0</span></p></td></tr>
2852</tbody></table>
2853</details>
2854</div>
2855<ul>
2856<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
2857</ul>
2858<p>If <code>true</code>, a diagnostic report is generated on uncaught exception.</p>
2859
2860<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2861
2862<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">${report.reportOnUncaughtException}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2863
2864<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">${report.reportOnUncaughtException}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2865<h4><code>process.report.signal</code><span><a class="mark" href="#processreportsignal" id="processreportsignal">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_signal"></a></h4>
2866<div class="api_metadata">
2867<details class="changelog"><summary>History</summary>
2868<table>
2869<tbody><tr><th>Version</th><th>Changes</th></tr>
2870<tr><td>v13.12.0, v12.17.0</td>
2871<td><p>This API is no longer experimental.</p></td></tr>
2872<tr><td>v11.12.0</td>
2873<td><p><span>Added in: v11.12.0</span></p></td></tr>
2874</tbody></table>
2875</details>
2876</div>
2877<ul>
2878<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
2879</ul>
2880<p>The signal used to trigger the creation of a diagnostic report. Defaults to
2881<code>'SIGUSR2'</code>.</p>
2882
2883<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2884
2885<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report signal: <span class="hljs-subst">${report.signal}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2886
2887<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report signal: <span class="hljs-subst">${report.signal}</span>`</span>);</code><button class="copy-button">copy</button></pre>
2888<h4><code>process.report.writeReport([filename][, err])</code><span><a class="mark" href="#processreportwritereportfilename-err" id="processreportwritereportfilename-err">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_writereport_filename_err"></a></h4>
2889<div class="api_metadata">
2890<details class="changelog"><summary>History</summary>
2891<table>
2892<tbody><tr><th>Version</th><th>Changes</th></tr>
2893<tr><td>v13.12.0, v12.17.0</td>
2894<td><p>This API is no longer experimental.</p></td></tr>
2895<tr><td>v11.8.0</td>
2896<td><p><span>Added in: v11.8.0</span></p></td></tr>
2897</tbody></table>
2898</details>
2899</div>
2900<ul>
2901<li>
2902<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
2903should be a relative path, that will be appended to the directory specified in
2904<code>process.report.directory</code>, or the current working directory of the Node.js
2905process, if unspecified.</p>
2906</li>
2907<li>
2908<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>
2909</li>
2910<li>
2911<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>
2912</li>
2913</ul>
2914<p>Writes a diagnostic report to a file. If <code>filename</code> is not provided, the default
2915filename includes the date, time, PID, and a sequence number. The report's
2916JavaScript stack trace is taken from <code>err</code>, if present.</p>
2917<p>If the value of <code>filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>, the report is
2918written to the stdout or stderr of the process respectively.</p>
2919
2920<pre class="with-43-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2921
2922report.<span class="hljs-title function_">writeReport</span>();</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
2923
2924report.<span class="hljs-title function_">writeReport</span>();</code><button class="copy-button">copy</button></pre>
2925<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
2926</section><section><h3><code>process.resourceUsage()</code><span><a class="mark" href="#processresourceusage" id="processresourceusage">#</a></span><a aria-hidden="true" class="legacy" id="process_process_resourceusage"></a></h3>
2927<div class="api_metadata">
2928<span>Added in: v12.6.0</span>
2929</div>
2930<ul>
2931<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
2932values come from the <code>uv_getrusage</code> call which returns
2933a <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t"><code>uv_rusage_t</code> struct</a>.
2934<ul>
2935<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.
2936It is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().user</code></a>.</li>
2937<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.
2938It is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().system</code></a>.</li>
2939<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
2940size used in kilobytes.</li>
2941<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
2942any platform.</li>
2943<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
2944any platform.</li>
2945<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
2946any platform.</li>
2947<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
2948minor page faults for the process, see
2949<a href="https://en.wikipedia.org/wiki/Page_fault#Minor">this article for more details</a>.</li>
2950<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
2951major page faults for the process, see
2952<a href="https://en.wikipedia.org/wiki/Page_fault#Major">this article for more details</a>. This field is not
2953supported on Windows.</li>
2954<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
2955platform.</li>
2956<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
2957file system had to perform input.</li>
2958<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
2959file system had to perform output.</li>
2960<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
2961platform.</li>
2962<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
2963platform.</li>
2964<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
2965platform.</li>
2966<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
2967number of times a CPU context switch resulted due to a process voluntarily
2968giving up the processor before its time slice was completed (usually to
2969await availability of a resource). This field is not supported on Windows.</li>
2970<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
2971number of times a CPU context switch resulted due to a higher priority
2972process becoming runnable or because the current process exceeded its
2973time slice. This field is not supported on Windows.</li>
2974</ul>
2975</li>
2976</ul>
2977
2978<pre class="with-50-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { resourceUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
2979
2980<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>());
2981<span class="hljs-comment">/*
2982  Will output:
2983  {
2984    userCPUTime: 82872,
2985    systemCPUTime: 4143,
2986    maxRSS: 33164,
2987    sharedMemorySize: 0,
2988    unsharedDataSize: 0,
2989    unsharedStackSize: 0,
2990    minorPageFault: 2469,
2991    majorPageFault: 0,
2992    swappedOut: 0,
2993    fsRead: 0,
2994    fsWrite: 8,
2995    ipcSent: 0,
2996    ipcReceived: 0,
2997    signalsCount: 0,
2998    voluntaryContextSwitches: 79,
2999    involuntaryContextSwitches: 1
3000  }
3001*/</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { resourceUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3002
3003<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>());
3004<span class="hljs-comment">/*
3005  Will output:
3006  {
3007    userCPUTime: 82872,
3008    systemCPUTime: 4143,
3009    maxRSS: 33164,
3010    sharedMemorySize: 0,
3011    unsharedDataSize: 0,
3012    unsharedStackSize: 0,
3013    minorPageFault: 2469,
3014    majorPageFault: 0,
3015    swappedOut: 0,
3016    fsRead: 0,
3017    fsWrite: 8,
3018    ipcSent: 0,
3019    ipcReceived: 0,
3020    signalsCount: 0,
3021    voluntaryContextSwitches: 79,
3022    involuntaryContextSwitches: 1
3023  }
3024*/</span></code><button class="copy-button">copy</button></pre>
3025</section><section><h3><code>process.send(message[, sendHandle[, options]][, callback])</code><span><a class="mark" href="#processsendmessage-sendhandle-options-callback" id="processsendmessage-sendhandle-options-callback">#</a></span><a aria-hidden="true" class="legacy" id="process_process_send_message_sendhandle_options_callback"></a></h3>
3026<div class="api_metadata">
3027<span>Added in: v0.5.9</span>
3028</div>
3029<ul>
3030<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>
3031<li><code>sendHandle</code> <a href="net.html#class-netserver" class="type">&#x3C;net.Server></a> | <a href="net.html#class-netsocket" class="type">&#x3C;net.Socket></a></li>
3032<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
3033handles.<code>options</code> supports the following properties:
3034<ul>
3035<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
3036<code>net.Socket</code>. When <code>true</code>, the socket is kept open in the sending process.
3037<strong>Default:</strong> <code>false</code>.</li>
3038</ul>
3039</li>
3040<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>
3041<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
3042</ul>
3043<p>If Node.js is spawned with an IPC channel, the <code>process.send()</code> method can be
3044used to send messages to the parent process. Messages will be received as a
3045<a href="child_process.html#event-message"><code>'message'</code></a> event on the parent's <a href="child_process.html#class-childprocess"><code>ChildProcess</code></a> object.</p>
3046<p>If Node.js was not spawned with an IPC channel, <code>process.send</code> will be
3047<code>undefined</code>.</p>
3048<p>The message goes through serialization and parsing. The resulting message might
3049not be the same as what is originally sent.</p>
3050</section><section><h3><code>process.setegid(id)</code><span><a class="mark" href="#processsetegidid" id="processsetegidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setegid_id"></a></h3>
3051<div class="api_metadata">
3052<span>Added in: v2.0.0</span>
3053</div>
3054<ul>
3055<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>
3056</ul>
3057<p>The <code>process.setegid()</code> method sets the effective group identity of the process.
3058(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
3059name string. If a group name is specified, this method blocks while resolving
3060the associated a numeric ID.</p>
3061
3062<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3063
3064<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> &#x26;&#x26; process.<span class="hljs-property">setegid</span>) {
3065  <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>);
3066  <span class="hljs-keyword">try</span> {
3067    process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>);
3068    <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>);
3069  } <span class="hljs-keyword">catch</span> (err) {
3070    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
3071  }
3072}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3073
3074<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> &#x26;&#x26; process.<span class="hljs-property">setegid</span>) {
3075  <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>);
3076  <span class="hljs-keyword">try</span> {
3077    process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>);
3078    <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>);
3079  } <span class="hljs-keyword">catch</span> (err) {
3080    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
3081  }
3082}</code><button class="copy-button">copy</button></pre>
3083<p>This function is only available on POSIX platforms (i.e. not Windows or
3084Android).
3085This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
3086</section><section><h3><code>process.seteuid(id)</code><span><a class="mark" href="#processseteuidid" id="processseteuidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_seteuid_id"></a></h3>
3087<div class="api_metadata">
3088<span>Added in: v2.0.0</span>
3089</div>
3090<ul>
3091<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>
3092</ul>
3093<p>The <code>process.seteuid()</code> method sets the effective user identity of the process.
3094(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
3095string. If a username is specified, the method blocks while resolving the
3096associated numeric ID.</p>
3097
3098<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3099
3100<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> &#x26;&#x26; process.<span class="hljs-property">seteuid</span>) {
3101  <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>);
3102  <span class="hljs-keyword">try</span> {
3103    process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>);
3104    <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>);
3105  } <span class="hljs-keyword">catch</span> (err) {
3106    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
3107  }
3108}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3109
3110<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> &#x26;&#x26; process.<span class="hljs-property">seteuid</span>) {
3111  <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>);
3112  <span class="hljs-keyword">try</span> {
3113    process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>);
3114    <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>);
3115  } <span class="hljs-keyword">catch</span> (err) {
3116    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
3117  }
3118}</code><button class="copy-button">copy</button></pre>
3119<p>This function is only available on POSIX platforms (i.e. not Windows or
3120Android).
3121This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
3122</section><section><h3><code>process.setgid(id)</code><span><a class="mark" href="#processsetgidid" id="processsetgidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setgid_id"></a></h3>
3123<div class="api_metadata">
3124<span>Added in: v0.1.31</span>
3125</div>
3126<ul>
3127<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>
3128</ul>
3129<p>The <code>process.setgid()</code> method sets the group identity of the process. (See
3130<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
3131string. If a group name is specified, this method blocks while resolving the
3132associated numeric ID.</p>
3133
3134<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3135
3136<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> &#x26;&#x26; process.<span class="hljs-property">setgid</span>) {
3137  <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>);
3138  <span class="hljs-keyword">try</span> {
3139    process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>);
3140    <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>);
3141  } <span class="hljs-keyword">catch</span> (err) {
3142    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
3143  }
3144}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3145
3146<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> &#x26;&#x26; process.<span class="hljs-property">setgid</span>) {
3147  <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>);
3148  <span class="hljs-keyword">try</span> {
3149    process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>);
3150    <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>);
3151  } <span class="hljs-keyword">catch</span> (err) {
3152    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
3153  }
3154}</code><button class="copy-button">copy</button></pre>
3155<p>This function is only available on POSIX platforms (i.e. not Windows or
3156Android).
3157This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
3158</section><section><h3><code>process.setgroups(groups)</code><span><a class="mark" href="#processsetgroupsgroups" id="processsetgroupsgroups">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setgroups_groups"></a></h3>
3159<div class="api_metadata">
3160<span>Added in: v0.9.4</span>
3161</div>
3162<ul>
3163<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>
3164</ul>
3165<p>The <code>process.setgroups()</code> method sets the supplementary group IDs for the
3166Node.js process. This is a privileged operation that requires the Node.js
3167process to have <code>root</code> or the <code>CAP_SETGID</code> capability.</p>
3168<p>The <code>groups</code> array can contain numeric group IDs, group names, or both.</p>
3169
3170<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3171
3172<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> &#x26;&#x26; process.<span class="hljs-property">setgroups</span>) {
3173  <span class="hljs-keyword">try</span> {
3174    process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]);
3175    <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>
3176  } <span class="hljs-keyword">catch</span> (err) {
3177    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set groups: <span class="hljs-subst">${err}</span>`</span>);
3178  }
3179}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3180
3181<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> &#x26;&#x26; process.<span class="hljs-property">setgroups</span>) {
3182  <span class="hljs-keyword">try</span> {
3183    process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]);
3184    <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>
3185  } <span class="hljs-keyword">catch</span> (err) {
3186    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set groups: <span class="hljs-subst">${err}</span>`</span>);
3187  }
3188}</code><button class="copy-button">copy</button></pre>
3189<p>This function is only available on POSIX platforms (i.e. not Windows or
3190Android).
3191This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
3192</section><section><h3><code>process.setuid(id)</code><span><a class="mark" href="#processsetuidid" id="processsetuidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setuid_id"></a></h3>
3193<div class="api_metadata">
3194<span>Added in: v0.1.28</span>
3195</div>
3196<ul>
3197<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>
3198</ul>
3199<p>The <code>process.setuid(id)</code> method sets the user identity of the process. (See
3200<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.
3201If a username is specified, the method blocks while resolving the associated
3202numeric ID.</p>
3203
3204<pre class="with-40-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3205
3206<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> &#x26;&#x26; process.<span class="hljs-property">setuid</span>) {
3207  <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>);
3208  <span class="hljs-keyword">try</span> {
3209    process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>);
3210    <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>);
3211  } <span class="hljs-keyword">catch</span> (err) {
3212    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
3213  }
3214}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3215
3216<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> &#x26;&#x26; process.<span class="hljs-property">setuid</span>) {
3217  <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>);
3218  <span class="hljs-keyword">try</span> {
3219    process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>);
3220    <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>);
3221  } <span class="hljs-keyword">catch</span> (err) {
3222    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
3223  }
3224}</code><button class="copy-button">copy</button></pre>
3225<p>This function is only available on POSIX platforms (i.e. not Windows or
3226Android).
3227This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
3228</section><section><h3><code>process.setSourceMapsEnabled(val)</code><span><a class="mark" href="#processsetsourcemapsenabledval" id="processsetsourcemapsenabledval">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setsourcemapsenabled_val"></a></h3>
3229<div class="api_metadata">
3230<span>Added in: v16.6.0, v14.18.0</span>
3231</div>
3232<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
3233<ul>
3234<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>
3235</ul>
3236<p>This function enables or disables the <a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for
3237stack traces.</p>
3238<p>It provides same features as launching Node.js process with commandline options
3239<code>--enable-source-maps</code>.</p>
3240<p>Only source maps in JavaScript files that are loaded after source maps has been
3241enabled will be parsed and loaded.</p>
3242</section><section><h3><code>process.setUncaughtExceptionCaptureCallback(fn)</code><span><a class="mark" href="#processsetuncaughtexceptioncapturecallbackfn" id="processsetuncaughtexceptioncapturecallbackfn">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setuncaughtexceptioncapturecallback_fn"></a></h3>
3243<div class="api_metadata">
3244<span>Added in: v9.3.0</span>
3245</div>
3246<ul>
3247<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>
3248</ul>
3249<p>The <code>process.setUncaughtExceptionCaptureCallback()</code> function sets a function
3250that will be invoked when an uncaught exception occurs, which will receive the
3251exception value itself as its first argument.</p>
3252<p>If such a function is set, the <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event will
3253not be emitted. If <code>--abort-on-uncaught-exception</code> was passed from the
3254command line or set through <a href="v8.html#v8setflagsfromstringflags"><code>v8.setFlagsFromString()</code></a>, the process will
3255not abort. Actions configured to take place on exceptions such as report
3256generations will be affected too</p>
3257<p>To unset the capture function,
3258<code>process.setUncaughtExceptionCaptureCallback(null)</code> may be used. Calling this
3259method with a non-<code>null</code> argument while another capture function is set will
3260throw an error.</p>
3261<p>Using this function is mutually exclusive with using the deprecated
3262<a href="domain.html"><code>domain</code></a> built-in module.</p>
3263</section><section><h3><code>process.sourceMapsEnabled</code><span><a class="mark" href="#processsourcemapsenabled" id="processsourcemapsenabled">#</a></span><a aria-hidden="true" class="legacy" id="process_process_sourcemapsenabled"></a></h3>
3264<div class="api_metadata">
3265<span>Added in: v18.19.0</span>
3266</div>
3267<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
3268<ul>
3269<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
3270</ul>
3271<p>The <code>process.sourceMapsEnabled</code> property returns whether the
3272<a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for stack traces is enabled.</p>
3273</section><section><h3><code>process.stderr</code><span><a class="mark" href="#processstderr" id="processstderr">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stderr"></a></h3>
3274<ul>
3275<li><a href="stream.html#stream" class="type">&#x3C;Stream></a></li>
3276</ul>
3277<p>The <code>process.stderr</code> property returns a stream connected to
3278<code>stderr</code> (fd <code>2</code>). It is a <a href="net.html#class-netsocket"><code>net.Socket</code></a> (which is a <a href="stream.html#duplex-and-transform-streams">Duplex</a>
3279stream) unless fd <code>2</code> refers to a file, in which case it is
3280a <a href="stream.html#writable-streams">Writable</a> stream.</p>
3281<p><code>process.stderr</code> differs from other Node.js streams in important ways. See
3282<a href="#a-note-on-process-io">note on process I/O</a> for more information.</p>
3283<h4><code>process.stderr.fd</code><span><a class="mark" href="#processstderrfd" id="processstderrfd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stderr_fd"></a></h4>
3284<ul>
3285<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
3286</ul>
3287<p>This property refers to the value of underlying file descriptor of
3288<code>process.stderr</code>. The value is fixed at <code>2</code>. In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads,
3289this field does not exist.</p>
3290</section><section><h3><code>process.stdin</code><span><a class="mark" href="#processstdin" id="processstdin">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdin"></a></h3>
3291<ul>
3292<li><a href="stream.html#stream" class="type">&#x3C;Stream></a></li>
3293</ul>
3294<p>The <code>process.stdin</code> property returns a stream connected to
3295<code>stdin</code> (fd <code>0</code>). It is a <a href="net.html#class-netsocket"><code>net.Socket</code></a> (which is a <a href="stream.html#duplex-and-transform-streams">Duplex</a>
3296stream) unless fd <code>0</code> refers to a file, in which case it is
3297a <a href="stream.html#readable-streams">Readable</a> stream.</p>
3298<p>For details of how to read from <code>stdin</code> see <a href="stream.html#readablereadsize"><code>readable.read()</code></a>.</p>
3299<p>As a <a href="stream.html#duplex-and-transform-streams">Duplex</a> stream, <code>process.stdin</code> can also be used in "old" mode that
3300is compatible with scripts written for Node.js prior to v0.10.
3301For more information see <a href="stream.html#compatibility-with-older-nodejs-versions">Stream compatibility</a>.</p>
3302<p>In "old" streams mode the <code>stdin</code> stream is paused by default, so one
3303must call <code>process.stdin.resume()</code> to read from it. Note also that calling
3304<code>process.stdin.resume()</code> itself would switch stream to "old" mode.</p>
3305<h4><code>process.stdin.fd</code><span><a class="mark" href="#processstdinfd" id="processstdinfd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdin_fd"></a></h4>
3306<ul>
3307<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
3308</ul>
3309<p>This property refers to the value of underlying file descriptor of
3310<code>process.stdin</code>. The value is fixed at <code>0</code>. In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads,
3311this field does not exist.</p>
3312</section><section><h3><code>process.stdout</code><span><a class="mark" href="#processstdout" id="processstdout">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdout"></a></h3>
3313<ul>
3314<li><a href="stream.html#stream" class="type">&#x3C;Stream></a></li>
3315</ul>
3316<p>The <code>process.stdout</code> property returns a stream connected to
3317<code>stdout</code> (fd <code>1</code>). It is a <a href="net.html#class-netsocket"><code>net.Socket</code></a> (which is a <a href="stream.html#duplex-and-transform-streams">Duplex</a>
3318stream) unless fd <code>1</code> refers to a file, in which case it is
3319a <a href="stream.html#writable-streams">Writable</a> stream.</p>
3320<p>For example, to copy <code>process.stdin</code> to <code>process.stdout</code>:</p>
3321
3322<pre class="with-50-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { stdin, stdout } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3323
3324stdin.<span class="hljs-title function_">pipe</span>(stdout);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { stdin, stdout } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3325
3326stdin.<span class="hljs-title function_">pipe</span>(stdout);</code><button class="copy-button">copy</button></pre>
3327<p><code>process.stdout</code> differs from other Node.js streams in important ways. See
3328<a href="#a-note-on-process-io">note on process I/O</a> for more information.</p>
3329<h4><code>process.stdout.fd</code><span><a class="mark" href="#processstdoutfd" id="processstdoutfd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdout_fd"></a></h4>
3330<ul>
3331<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
3332</ul>
3333<p>This property refers to the value of underlying file descriptor of
3334<code>process.stdout</code>. The value is fixed at <code>1</code>. In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads,
3335this field does not exist.</p>
3336<h4>A note on process I/O<span><a class="mark" href="#a-note-on-process-io" id="a-note-on-process-io">#</a></span><a aria-hidden="true" class="legacy" id="process_a_note_on_process_i_o"></a></h4>
3337<p><code>process.stdout</code> and <code>process.stderr</code> differ from other Node.js streams in
3338important ways:</p>
3339<ol>
3340<li>They are used internally by <a href="console.html#consolelogdata-args"><code>console.log()</code></a> and <a href="console.html#consoleerrordata-args"><code>console.error()</code></a>,
3341respectively.</li>
3342<li>Writes may be synchronous depending on what the stream is connected to
3343and whether the system is Windows or POSIX:
3344<ul>
3345<li>Files: <em>synchronous</em> on Windows and POSIX</li>
3346<li>TTYs (Terminals): <em>asynchronous</em> on Windows, <em>synchronous</em> on POSIX</li>
3347<li>Pipes (and sockets): <em>synchronous</em> on Windows, <em>asynchronous</em> on POSIX</li>
3348</ul>
3349</li>
3350</ol>
3351<p>These behaviors are partly for historical reasons, as changing them would
3352create backward incompatibility, but they are also expected by some users.</p>
3353<p>Synchronous writes avoid problems such as output written with <code>console.log()</code> or
3354<code>console.error()</code> being unexpectedly interleaved, or not written at all if
3355<code>process.exit()</code> is called before an asynchronous write completes. See
3356<a href="#processexitcode"><code>process.exit()</code></a> for more information.</p>
3357<p><em><strong>Warning</strong></em>: Synchronous writes block the event loop until the write has
3358completed. This can be near instantaneous in the case of output to a file, but
3359under high system load, pipes that are not being read at the receiving end, or
3360with slow terminals or file systems, it's possible for the event loop to be
3361blocked often enough and long enough to have severe negative performance
3362impacts. This may not be a problem when writing to an interactive terminal
3363session, but consider this particularly careful when doing production logging to
3364the process output streams.</p>
3365<p>To check if a stream is connected to a <a href="tty.html#tty">TTY</a> context, check the <code>isTTY</code>
3366property.</p>
3367<p>For instance:</p>
3368<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdin.isTTY)"</span></span>
3369true
3370<span class="hljs-meta prompt_">$ </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>
3371false
3372<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span></span>
3373true
3374<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span> | <span class="hljs-built_in">cat</span></span>
3375false</code> <button class="copy-button">copy</button></pre>
3376<p>See the <a href="tty.html#tty">TTY</a> documentation for more information.</p>
3377</section><section><h3><code>process.throwDeprecation</code><span><a class="mark" href="#processthrowdeprecation" id="processthrowdeprecation">#</a></span><a aria-hidden="true" class="legacy" id="process_process_throwdeprecation"></a></h3>
3378<div class="api_metadata">
3379<span>Added in: v0.9.12</span>
3380</div>
3381<ul>
3382<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
3383</ul>
3384<p>The initial value of <code>process.throwDeprecation</code> indicates whether the
3385<code>--throw-deprecation</code> flag is set on the current Node.js process.
3386<code>process.throwDeprecation</code> is mutable, so whether or not deprecation
3387warnings result in errors may be altered at runtime. See the
3388documentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the
3389<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information.</p>
3390<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node --throw-deprecation -p <span class="hljs-string">"process.throwDeprecation"</span></span>
3391true
3392<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"process.throwDeprecation"</span></span>
3393undefined
3394<span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span>
3395<span class="hljs-meta prompt_">> </span><span class="language-bash">process.emitWarning(<span class="hljs-string">'test'</span>, <span class="hljs-string">'DeprecationWarning'</span>);</span>
3396undefined
3397<span class="hljs-meta prompt_">> </span><span class="language-bash">(node:26598) DeprecationWarning: <span class="hljs-built_in">test</span></span>
3398<span class="hljs-meta prompt_">> </span><span class="language-bash">process.throwDeprecation = <span class="hljs-literal">true</span>;</span>
3399true
3400<span class="hljs-meta prompt_">> </span><span class="language-bash">process.emitWarning(<span class="hljs-string">'test'</span>, <span class="hljs-string">'DeprecationWarning'</span>);</span>
3401Thrown:
3402[DeprecationWarning: test] { name: 'DeprecationWarning' }</code> <button class="copy-button">copy</button></pre>
3403</section><section><h3><code>process.title</code><span><a class="mark" href="#processtitle" id="processtitle">#</a></span><a aria-hidden="true" class="legacy" id="process_process_title"></a></h3>
3404<div class="api_metadata">
3405<span>Added in: v0.1.104</span>
3406</div>
3407<ul>
3408<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
3409</ul>
3410<p>The <code>process.title</code> property returns the current process title (i.e. returns
3411the current value of <code>ps</code>). Assigning a new value to <code>process.title</code> modifies
3412the current value of <code>ps</code>.</p>
3413<p>When a new value is assigned, different platforms will impose different maximum
3414length restrictions on the title. Usually such restrictions are quite limited.
3415For instance, on Linux and macOS, <code>process.title</code> is limited to the size of the
3416binary name plus the length of the command-line arguments because setting the
3417<code>process.title</code> overwrites the <code>argv</code> memory of the process. Node.js v0.8
3418allowed for longer process title strings by also overwriting the <code>environ</code>
3419memory but that was potentially insecure and confusing in some (rather obscure)
3420cases.</p>
3421<p>Assigning a value to <code>process.title</code> might not result in an accurate label
3422within process manager applications such as macOS Activity Monitor or Windows
3423Services Manager.</p>
3424</section><section><h3><code>process.traceDeprecation</code><span><a class="mark" href="#processtracedeprecation" id="processtracedeprecation">#</a></span><a aria-hidden="true" class="legacy" id="process_process_tracedeprecation"></a></h3>
3425<div class="api_metadata">
3426<span>Added in: v0.8.0</span>
3427</div>
3428<ul>
3429<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
3430</ul>
3431<p>The <code>process.traceDeprecation</code> property indicates whether the
3432<code>--trace-deprecation</code> flag is set on the current Node.js process. See the
3433documentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the
3434<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this
3435flag's behavior.</p>
3436</section><section><h3><code>process.umask()</code><span><a class="mark" href="#processumask" id="processumask">#</a></span><a aria-hidden="true" class="legacy" id="process_process_umask"></a></h3>
3437<div class="api_metadata">
3438<details class="changelog"><summary>History</summary>
3439<table>
3440<tbody><tr><th>Version</th><th>Changes</th></tr>
3441<tr><td>v14.0.0, v12.19.0</td>
3442<td><p>Calling <code>process.umask()</code> with no arguments is deprecated.</p></td></tr>
3443<tr><td>v0.1.19</td>
3444<td><p><span>Added in: v0.1.19</span></p></td></tr>
3445</tbody></table>
3446</details>
3447</div>
3448<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated. Calling <code>process.umask()</code> with no argument causes
3449the process-wide umask to be written twice. This introduces a race condition
3450between threads, and is a potential security vulnerability. There is no safe,
3451cross-platform alternative API.</div><p></p>
3452<p><code>process.umask()</code> returns the Node.js process's file mode creation mask. Child
3453processes inherit the mask from the parent process.</p>
3454</section><section><h3><code>process.umask(mask)</code><span><a class="mark" href="#processumaskmask" id="processumaskmask">#</a></span><a aria-hidden="true" class="legacy" id="process_process_umask_mask"></a></h3>
3455<div class="api_metadata">
3456<span>Added in: v0.1.19</span>
3457</div>
3458<ul>
3459<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>
3460</ul>
3461<p><code>process.umask(mask)</code> sets the Node.js process's file mode creation mask. Child
3462processes inherit the mask from the parent process. Returns the previous mask.</p>
3463
3464<pre class="with-42-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { umask } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3465
3466<span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>;
3467<span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask);
3468<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(
3469  <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>,
3470);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { umask } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3471
3472<span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>;
3473<span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask);
3474<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(
3475  <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>,
3476);</code><button class="copy-button">copy</button></pre>
3477<p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, <code>process.umask(mask)</code> will throw an exception.</p>
3478</section><section><h3><code>process.uptime()</code><span><a class="mark" href="#processuptime" id="processuptime">#</a></span><a aria-hidden="true" class="legacy" id="process_process_uptime"></a></h3>
3479<div class="api_metadata">
3480<span>Added in: v0.5.0</span>
3481</div>
3482<ul>
3483<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
3484</ul>
3485<p>The <code>process.uptime()</code> method returns the number of seconds the current Node.js
3486process has been running.</p>
3487<p>The return value includes fractions of a second. Use <code>Math.floor()</code> to get whole
3488seconds.</p>
3489</section><section><h3><code>process.version</code><span><a class="mark" href="#processversion" id="processversion">#</a></span><a aria-hidden="true" class="legacy" id="process_process_version"></a></h3>
3490<div class="api_metadata">
3491<span>Added in: v0.1.3</span>
3492</div>
3493<ul>
3494<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
3495</ul>
3496<p>The <code>process.version</code> property contains the Node.js version string.</p>
3497
3498<pre class="with-44-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { version } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3499
3500<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Version: <span class="hljs-subst">${version}</span>`</span>);
3501<span class="hljs-comment">// Version: v14.8.0</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { version } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3502
3503<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Version: <span class="hljs-subst">${version}</span>`</span>);
3504<span class="hljs-comment">// Version: v14.8.0</span></code><button class="copy-button">copy</button></pre>
3505<p>To get the version string without the prepended <em>v</em>, use
3506<code>process.versions.node</code>.</p>
3507</section><section><h3><code>process.versions</code><span><a class="mark" href="#processversions" id="processversions">#</a></span><a aria-hidden="true" class="legacy" id="process_process_versions"></a></h3>
3508<div class="api_metadata">
3509<details class="changelog"><summary>History</summary>
3510<table>
3511<tbody><tr><th>Version</th><th>Changes</th></tr>
3512<tr><td>v9.0.0</td>
3513<td><p>The <code>v8</code> property now includes a Node.js specific suffix.</p></td></tr>
3514<tr><td>v4.2.0</td>
3515<td><p>The <code>icu</code> property is now supported.</p></td></tr>
3516<tr><td>v0.2.0</td>
3517<td><p><span>Added in: v0.2.0</span></p></td></tr>
3518</tbody></table>
3519</details>
3520</div>
3521<ul>
3522<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
3523</ul>
3524<p>The <code>process.versions</code> property returns an object listing the version strings of
3525Node.js and its dependencies. <code>process.versions.modules</code> indicates the current
3526ABI version, which is increased whenever a C++ API changes. Node.js will refuse
3527to load modules that were compiled against a different module ABI version.</p>
3528
3529<pre class="with-45-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { versions } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
3530
3531<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(versions);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { versions } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
3532
3533<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(versions);</code><button class="copy-button">copy</button></pre>
3534<p>Will generate an object similar to:</p>
3535<pre><code class="language-console">{ node: '11.13.0',
3536  v8: '7.0.276.38-node.18',
3537  uv: '1.27.0',
3538  zlib: '1.2.11',
3539  brotli: '1.0.7',
3540  ares: '1.15.0',
3541  modules: '67',
3542  nghttp2: '1.34.0',
3543  napi: '4',
3544  llhttp: '1.1.1',
3545  openssl: '1.1.1b',
3546  cldr: '34.0',
3547  icu: '63.1',
3548  tz: '2018e',
3549  unicode: '11.0' }</code> <button class="copy-button">copy</button></pre>
3550</section><section><h3>Exit codes<span><a class="mark" href="#exit-codes" id="exit-codes">#</a></span><a aria-hidden="true" class="legacy" id="process_exit_codes"></a></h3>
3551<p>Node.js will normally exit with a <code>0</code> status code when no more async
3552operations are pending. The following status codes are used in other
3553cases:</p>
3554<ul>
3555<li><code>1</code> <strong>Uncaught Fatal Exception</strong>: There was an uncaught exception,
3556and it was not handled by a domain or an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event
3557handler.</li>
3558<li><code>2</code>: Unused (reserved by Bash for builtin misuse)</li>
3559<li><code>3</code> <strong>Internal JavaScript Parse Error</strong>: The JavaScript source code
3560internal in the Node.js bootstrapping process caused a parse error. This
3561is extremely rare, and generally can only happen during development
3562of Node.js itself.</li>
3563<li><code>4</code> <strong>Internal JavaScript Evaluation Failure</strong>: The JavaScript
3564source code internal in the Node.js bootstrapping process failed to
3565return a function value when evaluated. This is extremely rare, and
3566generally can only happen during development of Node.js itself.</li>
3567<li><code>5</code> <strong>Fatal Error</strong>: There was a fatal unrecoverable error in V8.
3568Typically a message will be printed to stderr with the prefix <code>FATAL ERROR</code>.</li>
3569<li><code>6</code> <strong>Non-function Internal Exception Handler</strong>: There was an
3570uncaught exception, but the internal fatal exception handler
3571function was somehow set to a non-function, and could not be called.</li>
3572<li><code>7</code> <strong>Internal Exception Handler Run-Time Failure</strong>: There was an
3573uncaught exception, and the internal fatal exception handler
3574function itself threw an error while attempting to handle it. This
3575can happen, for example, if an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> or
3576<code>domain.on('error')</code> handler throws an error.</li>
3577<li><code>8</code>: Unused. In previous versions of Node.js, exit code 8 sometimes
3578indicated an uncaught exception.</li>
3579<li><code>9</code> <strong>Invalid Argument</strong>: Either an unknown option was specified,
3580or an option requiring a value was provided without a value.</li>
3581<li><code>10</code> <strong>Internal JavaScript Run-Time Failure</strong>: The JavaScript
3582source code internal in the Node.js bootstrapping process threw an error
3583when the bootstrapping function was called. This is extremely rare,
3584and generally can only happen during development of Node.js itself.</li>
3585<li><code>12</code> <strong>Invalid Debug Argument</strong>: The <code>--inspect</code> and/or <code>--inspect-brk</code>
3586options were set, but the port number chosen was invalid or unavailable.</li>
3587<li><code>13</code> <strong>Unfinished Top-Level Await</strong>: <code>await</code> was used outside of a function
3588in the top-level code, but the passed <code>Promise</code> never resolved.</li>
3589<li><code>14</code> <strong>Snapshot Failure</strong>: Node.js was started to build a V8 startup
3590snapshot and it failed because certain requirements of the state of
3591the application were not met.</li>
3592<li><code>>128</code> <strong>Signal Exits</strong>: If Node.js receives a fatal signal such as
3593<code>SIGKILL</code> or <code>SIGHUP</code>, then its exit code will be <code>128</code> plus the
3594value of the signal code. This is a standard POSIX practice, since
3595exit codes are defined to be 7-bit integers, and signal exits set
3596the high-order bit, and then contain the value of the signal code.
3597For example, signal <code>SIGABRT</code> has value <code>6</code>, so the expected exit
3598code will be <code>128</code> + <code>6</code>, or <code>134</code>.</li>
3599</ul></section>
3600        <!-- API END -->
3601      </div>
3602    </div>
3603  </div>
3604</body>
3605</html>
3606