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