11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html lang="en">
31cb0ef41Sopenharmony_ci<head>
41cb0ef41Sopenharmony_ci  <meta charset="utf-8">
51cb0ef41Sopenharmony_ci  <meta name="viewport" content="width=device-width">
61cb0ef41Sopenharmony_ci  <meta name="nodejs.org:node-version" content="v18.20.1">
71cb0ef41Sopenharmony_ci  <title>Process | Node.js v18.20.1 Documentation</title>
81cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
91cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/style.css">
101cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/hljs.css">
111cb0ef41Sopenharmony_ci  <link rel="canonical" href="https://nodejs.org/api/process.html">
121cb0ef41Sopenharmony_ci  <script async defer src="assets/api.js" type="text/javascript"></script>
131cb0ef41Sopenharmony_ci  <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>
141cb0ef41Sopenharmony_ci</head>
151cb0ef41Sopenharmony_ci<body class="alt apidoc" id="api-section-process">
161cb0ef41Sopenharmony_ci  <div id="content" class="clearfix">
171cb0ef41Sopenharmony_ci    <div id="column2" class="interior">
181cb0ef41Sopenharmony_ci      <div id="intro" class="interior">
191cb0ef41Sopenharmony_ci        <a href="/" title="Go back to the home page">
201cb0ef41Sopenharmony_ci          Node.js
211cb0ef41Sopenharmony_ci        </a>
221cb0ef41Sopenharmony_ci      </div>
231cb0ef41Sopenharmony_ci      <ul>
241cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
251cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
261cb0ef41Sopenharmony_ci</ul>
271cb0ef41Sopenharmony_ci<hr class="line">
281cb0ef41Sopenharmony_ci<ul>
291cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
301cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
311cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
321cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
331cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
341cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
351cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
361cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
371cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
381cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
391cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
401cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
411cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
421cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
431cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
441cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
451cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
461cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
471cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
481cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
491cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
501cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
511cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
521cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
531cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
541cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
551cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
561cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
571cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
581cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
591cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
601cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
611cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
621cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
631cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
641cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
651cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process active">Process</a></li>
661cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
671cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
681cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
691cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
701cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
711cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
721cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
731cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
741cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
751cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
761cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
771cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
781cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
791cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
801cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
811cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
821cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
831cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
841cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
851cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
861cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
871cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
881cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
891cb0ef41Sopenharmony_ci</ul>
901cb0ef41Sopenharmony_ci<hr class="line">
911cb0ef41Sopenharmony_ci<ul>
921cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
931cb0ef41Sopenharmony_ci</ul>
941cb0ef41Sopenharmony_ci    </div>
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci    <div id="column1" data-id="process" class="interior">
971cb0ef41Sopenharmony_ci      <header class="header">
981cb0ef41Sopenharmony_ci        <div class="header-container">
991cb0ef41Sopenharmony_ci          <h1>Node.js v18.20.1 documentation</h1>
1001cb0ef41Sopenharmony_ci          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
1011cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
1021cb0ef41Sopenharmony_ci              <path fill="none" d="M0 0h24v24H0z" />
1031cb0ef41Sopenharmony_ci              <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"/>
1041cb0ef41Sopenharmony_ci              <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"/>
1051cb0ef41Sopenharmony_ci            </svg>
1061cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
1071cb0ef41Sopenharmony_ci              <path d="M0 0h24v24H0z" fill="none" />
1081cb0ef41Sopenharmony_ci              <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"/>
1091cb0ef41Sopenharmony_ci            </svg>
1101cb0ef41Sopenharmony_ci          </button>
1111cb0ef41Sopenharmony_ci        </div>
1121cb0ef41Sopenharmony_ci        <div id="gtoc">
1131cb0ef41Sopenharmony_ci          <ul>
1141cb0ef41Sopenharmony_ci            <li class="pinned-header">Node.js v18.20.1</li>
1151cb0ef41Sopenharmony_ci            
1161cb0ef41Sopenharmony_ci    <li class="picker-header">
1171cb0ef41Sopenharmony_ci      <a href="#">
1181cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
1191cb0ef41Sopenharmony_ci        Table of contents
1201cb0ef41Sopenharmony_ci      </a>
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci      <div class="picker"><div class="toc"><ul>
1231cb0ef41Sopenharmony_ci<li><a href="#process">Process</a>
1241cb0ef41Sopenharmony_ci<ul>
1251cb0ef41Sopenharmony_ci<li><a href="#process-events">Process events</a>
1261cb0ef41Sopenharmony_ci<ul>
1271cb0ef41Sopenharmony_ci<li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li>
1281cb0ef41Sopenharmony_ci<li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li>
1291cb0ef41Sopenharmony_ci<li><a href="#event-exit">Event: <code>'exit'</code></a></li>
1301cb0ef41Sopenharmony_ci<li><a href="#event-message">Event: <code>'message'</code></a></li>
1311cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li>
1321cb0ef41Sopenharmony_ci<li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li>
1331cb0ef41Sopenharmony_ci<li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a>
1341cb0ef41Sopenharmony_ci<ul>
1351cb0ef41Sopenharmony_ci<li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li>
1361cb0ef41Sopenharmony_ci</ul>
1371cb0ef41Sopenharmony_ci</li>
1381cb0ef41Sopenharmony_ci<li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li>
1391cb0ef41Sopenharmony_ci<li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li>
1401cb0ef41Sopenharmony_ci<li><a href="#event-warning">Event: <code>'warning'</code></a></li>
1411cb0ef41Sopenharmony_ci<li><a href="#event-worker">Event: <code>'worker'</code></a>
1421cb0ef41Sopenharmony_ci<ul>
1431cb0ef41Sopenharmony_ci<li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li>
1441cb0ef41Sopenharmony_ci<li><a href="#nodejs-warning-names">Node.js warning names</a></li>
1451cb0ef41Sopenharmony_ci</ul>
1461cb0ef41Sopenharmony_ci</li>
1471cb0ef41Sopenharmony_ci<li><a href="#signal-events">Signal events</a></li>
1481cb0ef41Sopenharmony_ci</ul>
1491cb0ef41Sopenharmony_ci</li>
1501cb0ef41Sopenharmony_ci<li><a href="#processabort"><code>process.abort()</code></a></li>
1511cb0ef41Sopenharmony_ci<li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li>
1521cb0ef41Sopenharmony_ci<li><a href="#processarch"><code>process.arch</code></a></li>
1531cb0ef41Sopenharmony_ci<li><a href="#processargv"><code>process.argv</code></a></li>
1541cb0ef41Sopenharmony_ci<li><a href="#processargv0"><code>process.argv0</code></a></li>
1551cb0ef41Sopenharmony_ci<li><a href="#processchannel"><code>process.channel</code></a>
1561cb0ef41Sopenharmony_ci<ul>
1571cb0ef41Sopenharmony_ci<li><a href="#processchannelref"><code>process.channel.ref()</code></a></li>
1581cb0ef41Sopenharmony_ci<li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li>
1591cb0ef41Sopenharmony_ci</ul>
1601cb0ef41Sopenharmony_ci</li>
1611cb0ef41Sopenharmony_ci<li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li>
1621cb0ef41Sopenharmony_ci<li><a href="#processconfig"><code>process.config</code></a></li>
1631cb0ef41Sopenharmony_ci<li><a href="#processconnected"><code>process.connected</code></a></li>
1641cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li>
1651cb0ef41Sopenharmony_ci<li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li>
1661cb0ef41Sopenharmony_ci<li><a href="#processcwd"><code>process.cwd()</code></a></li>
1671cb0ef41Sopenharmony_ci<li><a href="#processdebugport"><code>process.debugPort</code></a></li>
1681cb0ef41Sopenharmony_ci<li><a href="#processdisconnect"><code>process.disconnect()</code></a></li>
1691cb0ef41Sopenharmony_ci<li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li>
1701cb0ef41Sopenharmony_ci<li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li>
1711cb0ef41Sopenharmony_ci<li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a>
1721cb0ef41Sopenharmony_ci<ul>
1731cb0ef41Sopenharmony_ci<li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li>
1741cb0ef41Sopenharmony_ci</ul>
1751cb0ef41Sopenharmony_ci</li>
1761cb0ef41Sopenharmony_ci<li><a href="#processenv"><code>process.env</code></a></li>
1771cb0ef41Sopenharmony_ci<li><a href="#processexecargv"><code>process.execArgv</code></a></li>
1781cb0ef41Sopenharmony_ci<li><a href="#processexecpath"><code>process.execPath</code></a></li>
1791cb0ef41Sopenharmony_ci<li><a href="#processexitcode"><code>process.exit([code])</code></a></li>
1801cb0ef41Sopenharmony_ci<li><a href="#processexitcode_1"><code>process.exitCode</code></a></li>
1811cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li>
1821cb0ef41Sopenharmony_ci<li><a href="#processgetegid"><code>process.getegid()</code></a></li>
1831cb0ef41Sopenharmony_ci<li><a href="#processgeteuid"><code>process.geteuid()</code></a></li>
1841cb0ef41Sopenharmony_ci<li><a href="#processgetgid"><code>process.getgid()</code></a></li>
1851cb0ef41Sopenharmony_ci<li><a href="#processgetgroups"><code>process.getgroups()</code></a></li>
1861cb0ef41Sopenharmony_ci<li><a href="#processgetuid"><code>process.getuid()</code></a></li>
1871cb0ef41Sopenharmony_ci<li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li>
1881cb0ef41Sopenharmony_ci<li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li>
1891cb0ef41Sopenharmony_ci<li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li>
1901cb0ef41Sopenharmony_ci<li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li>
1911cb0ef41Sopenharmony_ci<li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li>
1921cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li>
1931cb0ef41Sopenharmony_ci<li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li>
1941cb0ef41Sopenharmony_ci<li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li>
1951cb0ef41Sopenharmony_ci<li><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a>
1961cb0ef41Sopenharmony_ci<ul>
1971cb0ef41Sopenharmony_ci<li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li>
1981cb0ef41Sopenharmony_ci</ul>
1991cb0ef41Sopenharmony_ci</li>
2001cb0ef41Sopenharmony_ci<li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li>
2011cb0ef41Sopenharmony_ci<li><a href="#processpid"><code>process.pid</code></a></li>
2021cb0ef41Sopenharmony_ci<li><a href="#processplatform"><code>process.platform</code></a></li>
2031cb0ef41Sopenharmony_ci<li><a href="#processppid"><code>process.ppid</code></a></li>
2041cb0ef41Sopenharmony_ci<li><a href="#processrelease"><code>process.release</code></a></li>
2051cb0ef41Sopenharmony_ci<li><a href="#processreport"><code>process.report</code></a>
2061cb0ef41Sopenharmony_ci<ul>
2071cb0ef41Sopenharmony_ci<li><a href="#processreportcompact"><code>process.report.compact</code></a></li>
2081cb0ef41Sopenharmony_ci<li><a href="#processreportdirectory"><code>process.report.directory</code></a></li>
2091cb0ef41Sopenharmony_ci<li><a href="#processreportfilename"><code>process.report.filename</code></a></li>
2101cb0ef41Sopenharmony_ci<li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li>
2111cb0ef41Sopenharmony_ci<li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li>
2121cb0ef41Sopenharmony_ci<li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li>
2131cb0ef41Sopenharmony_ci<li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li>
2141cb0ef41Sopenharmony_ci<li><a href="#processreportsignal"><code>process.report.signal</code></a></li>
2151cb0ef41Sopenharmony_ci<li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li>
2161cb0ef41Sopenharmony_ci</ul>
2171cb0ef41Sopenharmony_ci</li>
2181cb0ef41Sopenharmony_ci<li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li>
2191cb0ef41Sopenharmony_ci<li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li>
2201cb0ef41Sopenharmony_ci<li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li>
2211cb0ef41Sopenharmony_ci<li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li>
2221cb0ef41Sopenharmony_ci<li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li>
2231cb0ef41Sopenharmony_ci<li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li>
2241cb0ef41Sopenharmony_ci<li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li>
2251cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li>
2261cb0ef41Sopenharmony_ci<li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li>
2271cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li>
2281cb0ef41Sopenharmony_ci<li><a href="#processstderr"><code>process.stderr</code></a>
2291cb0ef41Sopenharmony_ci<ul>
2301cb0ef41Sopenharmony_ci<li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li>
2311cb0ef41Sopenharmony_ci</ul>
2321cb0ef41Sopenharmony_ci</li>
2331cb0ef41Sopenharmony_ci<li><a href="#processstdin"><code>process.stdin</code></a>
2341cb0ef41Sopenharmony_ci<ul>
2351cb0ef41Sopenharmony_ci<li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li>
2361cb0ef41Sopenharmony_ci</ul>
2371cb0ef41Sopenharmony_ci</li>
2381cb0ef41Sopenharmony_ci<li><a href="#processstdout"><code>process.stdout</code></a>
2391cb0ef41Sopenharmony_ci<ul>
2401cb0ef41Sopenharmony_ci<li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li>
2411cb0ef41Sopenharmony_ci<li><a href="#a-note-on-process-io">A note on process I/O</a></li>
2421cb0ef41Sopenharmony_ci</ul>
2431cb0ef41Sopenharmony_ci</li>
2441cb0ef41Sopenharmony_ci<li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li>
2451cb0ef41Sopenharmony_ci<li><a href="#processtitle"><code>process.title</code></a></li>
2461cb0ef41Sopenharmony_ci<li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li>
2471cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li>
2481cb0ef41Sopenharmony_ci<li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li>
2491cb0ef41Sopenharmony_ci<li><a href="#processuptime"><code>process.uptime()</code></a></li>
2501cb0ef41Sopenharmony_ci<li><a href="#processversion"><code>process.version</code></a></li>
2511cb0ef41Sopenharmony_ci<li><a href="#processversions"><code>process.versions</code></a></li>
2521cb0ef41Sopenharmony_ci<li><a href="#exit-codes">Exit codes</a></li>
2531cb0ef41Sopenharmony_ci</ul>
2541cb0ef41Sopenharmony_ci</li>
2551cb0ef41Sopenharmony_ci</ul></div></div>
2561cb0ef41Sopenharmony_ci    </li>
2571cb0ef41Sopenharmony_ci  
2581cb0ef41Sopenharmony_ci            
2591cb0ef41Sopenharmony_ci    <li class="picker-header">
2601cb0ef41Sopenharmony_ci      <a href="#">
2611cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2621cb0ef41Sopenharmony_ci        Index
2631cb0ef41Sopenharmony_ci      </a>
2641cb0ef41Sopenharmony_ci
2651cb0ef41Sopenharmony_ci      <div class="picker"><ul>
2661cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
2671cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
2681cb0ef41Sopenharmony_ci
2691cb0ef41Sopenharmony_ci      <li>
2701cb0ef41Sopenharmony_ci        <a href="index.html">Index</a>
2711cb0ef41Sopenharmony_ci      </li>
2721cb0ef41Sopenharmony_ci    </ul>
2731cb0ef41Sopenharmony_ci  
2741cb0ef41Sopenharmony_ci<hr class="line">
2751cb0ef41Sopenharmony_ci<ul>
2761cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
2771cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
2781cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
2791cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
2801cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
2811cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
2821cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
2831cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
2841cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
2851cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
2861cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
2871cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
2881cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
2891cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
2901cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
2911cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
2921cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
2931cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
2941cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
2951cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
2961cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
2971cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
2981cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
2991cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
3001cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
3011cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
3021cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
3031cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
3041cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
3051cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
3061cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
3071cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
3081cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
3091cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
3101cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
3111cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
3121cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process active">Process</a></li>
3131cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
3141cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
3151cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
3161cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
3171cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
3181cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
3191cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
3201cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
3211cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
3221cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
3231cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
3241cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
3251cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
3261cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
3271cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
3281cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
3291cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
3301cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
3311cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
3321cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
3331cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
3341cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
3351cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
3361cb0ef41Sopenharmony_ci</ul>
3371cb0ef41Sopenharmony_ci<hr class="line">
3381cb0ef41Sopenharmony_ci<ul>
3391cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
3401cb0ef41Sopenharmony_ci</ul></div>
3411cb0ef41Sopenharmony_ci    </li>
3421cb0ef41Sopenharmony_ci  
3431cb0ef41Sopenharmony_ci            
3441cb0ef41Sopenharmony_ci    <li class="picker-header">
3451cb0ef41Sopenharmony_ci      <a href="#">
3461cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
3471cb0ef41Sopenharmony_ci        Other versions
3481cb0ef41Sopenharmony_ci      </a>
3491cb0ef41Sopenharmony_ci      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/process.html">21.x</a></li>
3501cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v20.x/api/process.html">20.x <b>LTS</b></a></li>
3511cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v19.x/api/process.html">19.x</a></li>
3521cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v18.x/api/process.html">18.x <b>LTS</b></a></li>
3531cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v17.x/api/process.html">17.x</a></li>
3541cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v16.x/api/process.html">16.x</a></li>
3551cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v15.x/api/process.html">15.x</a></li>
3561cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v14.x/api/process.html">14.x</a></li>
3571cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v13.x/api/process.html">13.x</a></li>
3581cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v12.x/api/process.html">12.x</a></li>
3591cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v11.x/api/process.html">11.x</a></li>
3601cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v10.x/api/process.html">10.x</a></li>
3611cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v9.x/api/process.html">9.x</a></li>
3621cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v8.x/api/process.html">8.x</a></li>
3631cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v7.x/api/process.html">7.x</a></li>
3641cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v6.x/api/process.html">6.x</a></li>
3651cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v5.x/api/process.html">5.x</a></li>
3661cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v4.x/api/process.html">4.x</a></li>
3671cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/process.html">0.12.x</a></li>
3681cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/process.html">0.10.x</a></li></ol></div>
3691cb0ef41Sopenharmony_ci    </li>
3701cb0ef41Sopenharmony_ci  
3711cb0ef41Sopenharmony_ci            <li class="picker-header">
3721cb0ef41Sopenharmony_ci              <a href="#">
3731cb0ef41Sopenharmony_ci                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
3741cb0ef41Sopenharmony_ci                Options
3751cb0ef41Sopenharmony_ci              </a>
3761cb0ef41Sopenharmony_ci        
3771cb0ef41Sopenharmony_ci              <div class="picker">
3781cb0ef41Sopenharmony_ci                <ul>
3791cb0ef41Sopenharmony_ci                  <li>
3801cb0ef41Sopenharmony_ci                    <a href="all.html">View on single page</a>
3811cb0ef41Sopenharmony_ci                  </li>
3821cb0ef41Sopenharmony_ci                  <li>
3831cb0ef41Sopenharmony_ci                    <a href="process.json">View as JSON</a>
3841cb0ef41Sopenharmony_ci                  </li>
3851cb0ef41Sopenharmony_ci                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/process.md">Edit on GitHub</a></li>    
3861cb0ef41Sopenharmony_ci                </ul>
3871cb0ef41Sopenharmony_ci              </div>
3881cb0ef41Sopenharmony_ci            </li>
3891cb0ef41Sopenharmony_ci          </ul>
3901cb0ef41Sopenharmony_ci        </div>
3911cb0ef41Sopenharmony_ci        <hr>
3921cb0ef41Sopenharmony_ci      </header>
3931cb0ef41Sopenharmony_ci
3941cb0ef41Sopenharmony_ci      <details id="toc" open><summary>Table of contents</summary><ul>
3951cb0ef41Sopenharmony_ci<li><a href="#process">Process</a>
3961cb0ef41Sopenharmony_ci<ul>
3971cb0ef41Sopenharmony_ci<li><a href="#process-events">Process events</a>
3981cb0ef41Sopenharmony_ci<ul>
3991cb0ef41Sopenharmony_ci<li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li>
4001cb0ef41Sopenharmony_ci<li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li>
4011cb0ef41Sopenharmony_ci<li><a href="#event-exit">Event: <code>'exit'</code></a></li>
4021cb0ef41Sopenharmony_ci<li><a href="#event-message">Event: <code>'message'</code></a></li>
4031cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li>
4041cb0ef41Sopenharmony_ci<li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li>
4051cb0ef41Sopenharmony_ci<li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a>
4061cb0ef41Sopenharmony_ci<ul>
4071cb0ef41Sopenharmony_ci<li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li>
4081cb0ef41Sopenharmony_ci</ul>
4091cb0ef41Sopenharmony_ci</li>
4101cb0ef41Sopenharmony_ci<li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li>
4111cb0ef41Sopenharmony_ci<li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li>
4121cb0ef41Sopenharmony_ci<li><a href="#event-warning">Event: <code>'warning'</code></a></li>
4131cb0ef41Sopenharmony_ci<li><a href="#event-worker">Event: <code>'worker'</code></a>
4141cb0ef41Sopenharmony_ci<ul>
4151cb0ef41Sopenharmony_ci<li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li>
4161cb0ef41Sopenharmony_ci<li><a href="#nodejs-warning-names">Node.js warning names</a></li>
4171cb0ef41Sopenharmony_ci</ul>
4181cb0ef41Sopenharmony_ci</li>
4191cb0ef41Sopenharmony_ci<li><a href="#signal-events">Signal events</a></li>
4201cb0ef41Sopenharmony_ci</ul>
4211cb0ef41Sopenharmony_ci</li>
4221cb0ef41Sopenharmony_ci<li><a href="#processabort"><code>process.abort()</code></a></li>
4231cb0ef41Sopenharmony_ci<li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li>
4241cb0ef41Sopenharmony_ci<li><a href="#processarch"><code>process.arch</code></a></li>
4251cb0ef41Sopenharmony_ci<li><a href="#processargv"><code>process.argv</code></a></li>
4261cb0ef41Sopenharmony_ci<li><a href="#processargv0"><code>process.argv0</code></a></li>
4271cb0ef41Sopenharmony_ci<li><a href="#processchannel"><code>process.channel</code></a>
4281cb0ef41Sopenharmony_ci<ul>
4291cb0ef41Sopenharmony_ci<li><a href="#processchannelref"><code>process.channel.ref()</code></a></li>
4301cb0ef41Sopenharmony_ci<li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li>
4311cb0ef41Sopenharmony_ci</ul>
4321cb0ef41Sopenharmony_ci</li>
4331cb0ef41Sopenharmony_ci<li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li>
4341cb0ef41Sopenharmony_ci<li><a href="#processconfig"><code>process.config</code></a></li>
4351cb0ef41Sopenharmony_ci<li><a href="#processconnected"><code>process.connected</code></a></li>
4361cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li>
4371cb0ef41Sopenharmony_ci<li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li>
4381cb0ef41Sopenharmony_ci<li><a href="#processcwd"><code>process.cwd()</code></a></li>
4391cb0ef41Sopenharmony_ci<li><a href="#processdebugport"><code>process.debugPort</code></a></li>
4401cb0ef41Sopenharmony_ci<li><a href="#processdisconnect"><code>process.disconnect()</code></a></li>
4411cb0ef41Sopenharmony_ci<li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li>
4421cb0ef41Sopenharmony_ci<li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li>
4431cb0ef41Sopenharmony_ci<li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a>
4441cb0ef41Sopenharmony_ci<ul>
4451cb0ef41Sopenharmony_ci<li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li>
4461cb0ef41Sopenharmony_ci</ul>
4471cb0ef41Sopenharmony_ci</li>
4481cb0ef41Sopenharmony_ci<li><a href="#processenv"><code>process.env</code></a></li>
4491cb0ef41Sopenharmony_ci<li><a href="#processexecargv"><code>process.execArgv</code></a></li>
4501cb0ef41Sopenharmony_ci<li><a href="#processexecpath"><code>process.execPath</code></a></li>
4511cb0ef41Sopenharmony_ci<li><a href="#processexitcode"><code>process.exit([code])</code></a></li>
4521cb0ef41Sopenharmony_ci<li><a href="#processexitcode_1"><code>process.exitCode</code></a></li>
4531cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li>
4541cb0ef41Sopenharmony_ci<li><a href="#processgetegid"><code>process.getegid()</code></a></li>
4551cb0ef41Sopenharmony_ci<li><a href="#processgeteuid"><code>process.geteuid()</code></a></li>
4561cb0ef41Sopenharmony_ci<li><a href="#processgetgid"><code>process.getgid()</code></a></li>
4571cb0ef41Sopenharmony_ci<li><a href="#processgetgroups"><code>process.getgroups()</code></a></li>
4581cb0ef41Sopenharmony_ci<li><a href="#processgetuid"><code>process.getuid()</code></a></li>
4591cb0ef41Sopenharmony_ci<li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li>
4601cb0ef41Sopenharmony_ci<li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li>
4611cb0ef41Sopenharmony_ci<li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li>
4621cb0ef41Sopenharmony_ci<li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li>
4631cb0ef41Sopenharmony_ci<li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li>
4641cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li>
4651cb0ef41Sopenharmony_ci<li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li>
4661cb0ef41Sopenharmony_ci<li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li>
4671cb0ef41Sopenharmony_ci<li><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a>
4681cb0ef41Sopenharmony_ci<ul>
4691cb0ef41Sopenharmony_ci<li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li>
4701cb0ef41Sopenharmony_ci</ul>
4711cb0ef41Sopenharmony_ci</li>
4721cb0ef41Sopenharmony_ci<li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li>
4731cb0ef41Sopenharmony_ci<li><a href="#processpid"><code>process.pid</code></a></li>
4741cb0ef41Sopenharmony_ci<li><a href="#processplatform"><code>process.platform</code></a></li>
4751cb0ef41Sopenharmony_ci<li><a href="#processppid"><code>process.ppid</code></a></li>
4761cb0ef41Sopenharmony_ci<li><a href="#processrelease"><code>process.release</code></a></li>
4771cb0ef41Sopenharmony_ci<li><a href="#processreport"><code>process.report</code></a>
4781cb0ef41Sopenharmony_ci<ul>
4791cb0ef41Sopenharmony_ci<li><a href="#processreportcompact"><code>process.report.compact</code></a></li>
4801cb0ef41Sopenharmony_ci<li><a href="#processreportdirectory"><code>process.report.directory</code></a></li>
4811cb0ef41Sopenharmony_ci<li><a href="#processreportfilename"><code>process.report.filename</code></a></li>
4821cb0ef41Sopenharmony_ci<li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li>
4831cb0ef41Sopenharmony_ci<li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li>
4841cb0ef41Sopenharmony_ci<li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li>
4851cb0ef41Sopenharmony_ci<li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li>
4861cb0ef41Sopenharmony_ci<li><a href="#processreportsignal"><code>process.report.signal</code></a></li>
4871cb0ef41Sopenharmony_ci<li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li>
4881cb0ef41Sopenharmony_ci</ul>
4891cb0ef41Sopenharmony_ci</li>
4901cb0ef41Sopenharmony_ci<li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li>
4911cb0ef41Sopenharmony_ci<li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li>
4921cb0ef41Sopenharmony_ci<li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li>
4931cb0ef41Sopenharmony_ci<li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li>
4941cb0ef41Sopenharmony_ci<li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li>
4951cb0ef41Sopenharmony_ci<li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li>
4961cb0ef41Sopenharmony_ci<li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li>
4971cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li>
4981cb0ef41Sopenharmony_ci<li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li>
4991cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li>
5001cb0ef41Sopenharmony_ci<li><a href="#processstderr"><code>process.stderr</code></a>
5011cb0ef41Sopenharmony_ci<ul>
5021cb0ef41Sopenharmony_ci<li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li>
5031cb0ef41Sopenharmony_ci</ul>
5041cb0ef41Sopenharmony_ci</li>
5051cb0ef41Sopenharmony_ci<li><a href="#processstdin"><code>process.stdin</code></a>
5061cb0ef41Sopenharmony_ci<ul>
5071cb0ef41Sopenharmony_ci<li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li>
5081cb0ef41Sopenharmony_ci</ul>
5091cb0ef41Sopenharmony_ci</li>
5101cb0ef41Sopenharmony_ci<li><a href="#processstdout"><code>process.stdout</code></a>
5111cb0ef41Sopenharmony_ci<ul>
5121cb0ef41Sopenharmony_ci<li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li>
5131cb0ef41Sopenharmony_ci<li><a href="#a-note-on-process-io">A note on process I/O</a></li>
5141cb0ef41Sopenharmony_ci</ul>
5151cb0ef41Sopenharmony_ci</li>
5161cb0ef41Sopenharmony_ci<li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li>
5171cb0ef41Sopenharmony_ci<li><a href="#processtitle"><code>process.title</code></a></li>
5181cb0ef41Sopenharmony_ci<li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li>
5191cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li>
5201cb0ef41Sopenharmony_ci<li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li>
5211cb0ef41Sopenharmony_ci<li><a href="#processuptime"><code>process.uptime()</code></a></li>
5221cb0ef41Sopenharmony_ci<li><a href="#processversion"><code>process.version</code></a></li>
5231cb0ef41Sopenharmony_ci<li><a href="#processversions"><code>process.versions</code></a></li>
5241cb0ef41Sopenharmony_ci<li><a href="#exit-codes">Exit codes</a></li>
5251cb0ef41Sopenharmony_ci</ul>
5261cb0ef41Sopenharmony_ci</li>
5271cb0ef41Sopenharmony_ci</ul></details>
5281cb0ef41Sopenharmony_ci
5291cb0ef41Sopenharmony_ci      <div id="apicontent">
5301cb0ef41Sopenharmony_ci        <h2>Process<span><a class="mark" href="#process" id="process">#</a></span><a aria-hidden="true" class="legacy" id="process_process"></a></h2>
5311cb0ef41Sopenharmony_ci
5321cb0ef41Sopenharmony_ci
5331cb0ef41Sopenharmony_ci<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/process.js">lib/process.js</a></p>
5341cb0ef41Sopenharmony_ci<p>The <code>process</code> object provides information about, and control over, the current
5351cb0ef41Sopenharmony_ciNode.js process.</p>
5361cb0ef41Sopenharmony_ci
5371cb0ef41Sopenharmony_ci<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>
5381cb0ef41Sopenharmony_ci<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>
5391cb0ef41Sopenharmony_ci<p>The <code>process</code> object is an instance of <a href="events.html#class-eventemitter"><code>EventEmitter</code></a>.</p>
5401cb0ef41Sopenharmony_ci<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>
5411cb0ef41Sopenharmony_ci<div class="api_metadata">
5421cb0ef41Sopenharmony_ci<span>Added in: v0.11.12</span>
5431cb0ef41Sopenharmony_ci</div>
5441cb0ef41Sopenharmony_ci<p>The <code>'beforeExit'</code> event is emitted when Node.js empties its event loop and has
5451cb0ef41Sopenharmony_cino additional work to schedule. Normally, the Node.js process will exit when
5461cb0ef41Sopenharmony_cithere is no work scheduled, but a listener registered on the <code>'beforeExit'</code>
5471cb0ef41Sopenharmony_cievent can make asynchronous calls, and thereby cause the Node.js process to
5481cb0ef41Sopenharmony_cicontinue.</p>
5491cb0ef41Sopenharmony_ci<p>The listener callback function is invoked with the value of
5501cb0ef41Sopenharmony_ci<a href="#processexitcode_1"><code>process.exitCode</code></a> passed as the only argument.</p>
5511cb0ef41Sopenharmony_ci<p>The <code>'beforeExit'</code> event is <em>not</em> emitted for conditions causing explicit
5521cb0ef41Sopenharmony_citermination, such as calling <a href="#processexitcode"><code>process.exit()</code></a> or uncaught exceptions.</p>
5531cb0ef41Sopenharmony_ci<p>The <code>'beforeExit'</code> should <em>not</em> be used as an alternative to the <code>'exit'</code> event
5541cb0ef41Sopenharmony_ciunless the intention is to schedule additional work.</p>
5551cb0ef41Sopenharmony_ci
5561cb0ef41Sopenharmony_ci<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>;
5571cb0ef41Sopenharmony_ci
5581cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
5591cb0ef41Sopenharmony_ci  <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);
5601cb0ef41Sopenharmony_ci});
5611cb0ef41Sopenharmony_ci
5621cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
5631cb0ef41Sopenharmony_ci  <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);
5641cb0ef41Sopenharmony_ci});
5651cb0ef41Sopenharmony_ci
5661cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>);
5671cb0ef41Sopenharmony_ci
5681cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
5691cb0ef41Sopenharmony_ci<span class="hljs-comment">// This message is displayed first.</span>
5701cb0ef41Sopenharmony_ci<span class="hljs-comment">// Process beforeExit event with code: 0</span>
5711cb0ef41Sopenharmony_ci<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>);
5721cb0ef41Sopenharmony_ci
5731cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
5741cb0ef41Sopenharmony_ci  <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);
5751cb0ef41Sopenharmony_ci});
5761cb0ef41Sopenharmony_ci
5771cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
5781cb0ef41Sopenharmony_ci  <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);
5791cb0ef41Sopenharmony_ci});
5801cb0ef41Sopenharmony_ci
5811cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>);
5821cb0ef41Sopenharmony_ci
5831cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
5841cb0ef41Sopenharmony_ci<span class="hljs-comment">// This message is displayed first.</span>
5851cb0ef41Sopenharmony_ci<span class="hljs-comment">// Process beforeExit event with code: 0</span>
5861cb0ef41Sopenharmony_ci<span class="hljs-comment">// Process exit event with code: 0</span></code><button class="copy-button">copy</button></pre>
5871cb0ef41Sopenharmony_ci<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>
5881cb0ef41Sopenharmony_ci<div class="api_metadata">
5891cb0ef41Sopenharmony_ci<span>Added in: v0.7.7</span>
5901cb0ef41Sopenharmony_ci</div>
5911cb0ef41Sopenharmony_ci<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
5921cb0ef41Sopenharmony_ciand <a href="cluster.html">Cluster</a> documentation), the <code>'disconnect'</code> event will be emitted when
5931cb0ef41Sopenharmony_cithe IPC channel is closed.</p>
5941cb0ef41Sopenharmony_ci<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>
5951cb0ef41Sopenharmony_ci<div class="api_metadata">
5961cb0ef41Sopenharmony_ci<span>Added in: v0.1.7</span>
5971cb0ef41Sopenharmony_ci</div>
5981cb0ef41Sopenharmony_ci<ul>
5991cb0ef41Sopenharmony_ci<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>
6001cb0ef41Sopenharmony_ci</ul>
6011cb0ef41Sopenharmony_ci<p>The <code>'exit'</code> event is emitted when the Node.js process is about to exit as a
6021cb0ef41Sopenharmony_ciresult of either:</p>
6031cb0ef41Sopenharmony_ci<ul>
6041cb0ef41Sopenharmony_ci<li>The <code>process.exit()</code> method being called explicitly;</li>
6051cb0ef41Sopenharmony_ci<li>The Node.js event loop no longer having any additional work to perform.</li>
6061cb0ef41Sopenharmony_ci</ul>
6071cb0ef41Sopenharmony_ci<p>There is no way to prevent the exiting of the event loop at this point, and once
6081cb0ef41Sopenharmony_ciall <code>'exit'</code> listeners have finished running the Node.js process will terminate.</p>
6091cb0ef41Sopenharmony_ci<p>The listener callback function is invoked with the exit code specified either
6101cb0ef41Sopenharmony_ciby the <a href="#processexitcode_1"><code>process.exitCode</code></a> property, or the <code>exitCode</code> argument passed to the
6111cb0ef41Sopenharmony_ci<a href="#processexitcode"><code>process.exit()</code></a> method.</p>
6121cb0ef41Sopenharmony_ci
6131cb0ef41Sopenharmony_ci<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>;
6141cb0ef41Sopenharmony_ci
6151cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
6161cb0ef41Sopenharmony_ci  <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>);
6171cb0ef41Sopenharmony_ci});</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>);
6181cb0ef41Sopenharmony_ci
6191cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
6201cb0ef41Sopenharmony_ci  <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>);
6211cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
6221cb0ef41Sopenharmony_ci<p>Listener functions <strong>must</strong> only perform <strong>synchronous</strong> operations. The Node.js
6231cb0ef41Sopenharmony_ciprocess will exit immediately after calling the <code>'exit'</code> event listeners
6241cb0ef41Sopenharmony_cicausing any additional work still queued in the event loop to be abandoned.
6251cb0ef41Sopenharmony_ciIn the following example, for instance, the timeout will never occur:</p>
6261cb0ef41Sopenharmony_ci
6271cb0ef41Sopenharmony_ci<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>;
6281cb0ef41Sopenharmony_ci
6291cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
6301cb0ef41Sopenharmony_ci  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
6311cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>);
6321cb0ef41Sopenharmony_ci  }, <span class="hljs-number">0</span>);
6331cb0ef41Sopenharmony_ci});</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>);
6341cb0ef41Sopenharmony_ci
6351cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
6361cb0ef41Sopenharmony_ci  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
6371cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>);
6381cb0ef41Sopenharmony_ci  }, <span class="hljs-number">0</span>);
6391cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
6401cb0ef41Sopenharmony_ci<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>
6411cb0ef41Sopenharmony_ci<div class="api_metadata">
6421cb0ef41Sopenharmony_ci<span>Added in: v0.5.10</span>
6431cb0ef41Sopenharmony_ci</div>
6441cb0ef41Sopenharmony_ci<ul>
6451cb0ef41Sopenharmony_ci<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
6461cb0ef41Sopenharmony_cior a serializable primitive value.</li>
6471cb0ef41Sopenharmony_ci<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>
6481cb0ef41Sopenharmony_ciobject, or undefined.</li>
6491cb0ef41Sopenharmony_ci</ul>
6501cb0ef41Sopenharmony_ci<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
6511cb0ef41Sopenharmony_ciand <a href="cluster.html">Cluster</a> documentation), the <code>'message'</code> event is emitted whenever a
6521cb0ef41Sopenharmony_cimessage sent by a parent process using <a href="child_process.html#subprocesssendmessage-sendhandle-options-callback"><code>childprocess.send()</code></a> is received by
6531cb0ef41Sopenharmony_cithe child process.</p>
6541cb0ef41Sopenharmony_ci<p>The message goes through serialization and parsing. The resulting message might
6551cb0ef41Sopenharmony_cinot be the same as what is originally sent.</p>
6561cb0ef41Sopenharmony_ci<p>If the <code>serialization</code> option was set to <code>advanced</code> used when spawning the
6571cb0ef41Sopenharmony_ciprocess, the <code>message</code> argument can contain data that JSON is not able
6581cb0ef41Sopenharmony_cito represent.
6591cb0ef41Sopenharmony_ciSee <a href="child_process.html#advanced-serialization">Advanced serialization for <code>child_process</code></a> for more details.</p>
6601cb0ef41Sopenharmony_ci<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>
6611cb0ef41Sopenharmony_ci<div class="api_metadata">
6621cb0ef41Sopenharmony_ci<span>Added in: v10.12.0</span><span>Deprecated since: v17.6.0</span>
6631cb0ef41Sopenharmony_ci</div>
6641cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated</div><p></p>
6651cb0ef41Sopenharmony_ci<ul>
6661cb0ef41Sopenharmony_ci<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>
6671cb0ef41Sopenharmony_ci<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>
6681cb0ef41Sopenharmony_ci<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
6691cb0ef41Sopenharmony_cirejected after the original resolve.</li>
6701cb0ef41Sopenharmony_ci</ul>
6711cb0ef41Sopenharmony_ci<p>The <code>'multipleResolves'</code> event is emitted whenever a <code>Promise</code> has been either:</p>
6721cb0ef41Sopenharmony_ci<ul>
6731cb0ef41Sopenharmony_ci<li>Resolved more than once.</li>
6741cb0ef41Sopenharmony_ci<li>Rejected more than once.</li>
6751cb0ef41Sopenharmony_ci<li>Rejected after resolve.</li>
6761cb0ef41Sopenharmony_ci<li>Resolved after reject.</li>
6771cb0ef41Sopenharmony_ci</ul>
6781cb0ef41Sopenharmony_ci<p>This is useful for tracking potential errors in an application while using the
6791cb0ef41Sopenharmony_ci<code>Promise</code> constructor, as multiple resolutions are silently swallowed. However,
6801cb0ef41Sopenharmony_cithe occurrence of this event does not necessarily indicate an error. For
6811cb0ef41Sopenharmony_ciexample, <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>
6821cb0ef41Sopenharmony_ci<p>Because of the unreliability of the event in cases like the
6831cb0ef41Sopenharmony_ci<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>
6841cb0ef41Sopenharmony_ci
6851cb0ef41Sopenharmony_ci<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>;
6861cb0ef41Sopenharmony_ci
6871cb0ef41Sopenharmony_ciprocess.<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> {
6881cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason);
6891cb0ef41Sopenharmony_ci  <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>));
6901cb0ef41Sopenharmony_ci});
6911cb0ef41Sopenharmony_ci
6921cb0ef41Sopenharmony_ci<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
6931cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
6941cb0ef41Sopenharmony_ci    <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> {
6951cb0ef41Sopenharmony_ci      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>);
6961cb0ef41Sopenharmony_ci      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</span>);
6971cb0ef41Sopenharmony_ci      <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>));
6981cb0ef41Sopenharmony_ci    });
6991cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> {
7001cb0ef41Sopenharmony_ci    <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>);
7011cb0ef41Sopenharmony_ci  }
7021cb0ef41Sopenharmony_ci}
7031cb0ef41Sopenharmony_ci
7041cb0ef41Sopenharmony_ci<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>);
7051cb0ef41Sopenharmony_ci<span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span>
7061cb0ef41Sopenharmony_ci<span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span>
7071cb0ef41Sopenharmony_ci<span class="hljs-comment">//     at Promise (*)</span>
7081cb0ef41Sopenharmony_ci<span class="hljs-comment">//     at new Promise (&#x3C;anonymous>)</span>
7091cb0ef41Sopenharmony_ci<span class="hljs-comment">//     at main (*)</span>
7101cb0ef41Sopenharmony_ci<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>);
7111cb0ef41Sopenharmony_ci
7121cb0ef41Sopenharmony_ciprocess.<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> {
7131cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason);
7141cb0ef41Sopenharmony_ci  <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>));
7151cb0ef41Sopenharmony_ci});
7161cb0ef41Sopenharmony_ci
7171cb0ef41Sopenharmony_ci<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
7181cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
7191cb0ef41Sopenharmony_ci    <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> {
7201cb0ef41Sopenharmony_ci      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>);
7211cb0ef41Sopenharmony_ci      <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</span>);
7221cb0ef41Sopenharmony_ci      <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>));
7231cb0ef41Sopenharmony_ci    });
7241cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> {
7251cb0ef41Sopenharmony_ci    <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>);
7261cb0ef41Sopenharmony_ci  }
7271cb0ef41Sopenharmony_ci}
7281cb0ef41Sopenharmony_ci
7291cb0ef41Sopenharmony_ci<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>);
7301cb0ef41Sopenharmony_ci<span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span>
7311cb0ef41Sopenharmony_ci<span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span>
7321cb0ef41Sopenharmony_ci<span class="hljs-comment">//     at Promise (*)</span>
7331cb0ef41Sopenharmony_ci<span class="hljs-comment">//     at new Promise (&#x3C;anonymous>)</span>
7341cb0ef41Sopenharmony_ci<span class="hljs-comment">//     at main (*)</span>
7351cb0ef41Sopenharmony_ci<span class="hljs-comment">// First call</span></code><button class="copy-button">copy</button></pre>
7361cb0ef41Sopenharmony_ci<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>
7371cb0ef41Sopenharmony_ci<div class="api_metadata">
7381cb0ef41Sopenharmony_ci<span>Added in: v1.4.1</span>
7391cb0ef41Sopenharmony_ci</div>
7401cb0ef41Sopenharmony_ci<ul>
7411cb0ef41Sopenharmony_ci<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>
7421cb0ef41Sopenharmony_ci</ul>
7431cb0ef41Sopenharmony_ci<p>The <code>'rejectionHandled'</code> event is emitted whenever a <code>Promise</code> has been rejected
7441cb0ef41Sopenharmony_ciand 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
7451cb0ef41Sopenharmony_ciexample) later than one turn of the Node.js event loop.</p>
7461cb0ef41Sopenharmony_ci<p>The <code>Promise</code> object would have previously been emitted in an
7471cb0ef41Sopenharmony_ci<code>'unhandledRejection'</code> event, but during the course of processing gained a
7481cb0ef41Sopenharmony_cirejection handler.</p>
7491cb0ef41Sopenharmony_ci<p>There is no notion of a top level for a <code>Promise</code> chain at which rejections can
7501cb0ef41Sopenharmony_cialways be handled. Being inherently asynchronous in nature, a <code>Promise</code>
7511cb0ef41Sopenharmony_cirejection can be handled at a future point in time, possibly much later than
7521cb0ef41Sopenharmony_cithe event loop turn it takes for the <code>'unhandledRejection'</code> event to be emitted.</p>
7531cb0ef41Sopenharmony_ci<p>Another way of stating this is that, unlike in synchronous code where there is
7541cb0ef41Sopenharmony_cian ever-growing list of unhandled exceptions, with Promises there can be a
7551cb0ef41Sopenharmony_cigrowing-and-shrinking list of unhandled rejections.</p>
7561cb0ef41Sopenharmony_ci<p>In synchronous code, the <code>'uncaughtException'</code> event is emitted when the list of
7571cb0ef41Sopenharmony_ciunhandled exceptions grows.</p>
7581cb0ef41Sopenharmony_ci<p>In asynchronous code, the <code>'unhandledRejection'</code> event is emitted when the list
7591cb0ef41Sopenharmony_ciof unhandled rejections grows, and the <code>'rejectionHandled'</code> event is emitted
7601cb0ef41Sopenharmony_ciwhen the list of unhandled rejections shrinks.</p>
7611cb0ef41Sopenharmony_ci
7621cb0ef41Sopenharmony_ci<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>;
7631cb0ef41Sopenharmony_ci
7641cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
7651cb0ef41Sopenharmony_ciprocess.<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> {
7661cb0ef41Sopenharmony_ci  unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason);
7671cb0ef41Sopenharmony_ci});
7681cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> {
7691cb0ef41Sopenharmony_ci  unhandledRejections.<span class="hljs-title function_">delete</span>(promise);
7701cb0ef41Sopenharmony_ci});</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>);
7711cb0ef41Sopenharmony_ci
7721cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
7731cb0ef41Sopenharmony_ciprocess.<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> {
7741cb0ef41Sopenharmony_ci  unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason);
7751cb0ef41Sopenharmony_ci});
7761cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> {
7771cb0ef41Sopenharmony_ci  unhandledRejections.<span class="hljs-title function_">delete</span>(promise);
7781cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
7791cb0ef41Sopenharmony_ci<p>In this example, the <code>unhandledRejections</code> <code>Map</code> will grow and shrink over time,
7801cb0ef41Sopenharmony_cireflecting rejections that start unhandled and then become handled. It is
7811cb0ef41Sopenharmony_cipossible to record such errors in an error log, either periodically (which is
7821cb0ef41Sopenharmony_cilikely best for long-running application) or upon process exit (which is likely
7831cb0ef41Sopenharmony_cimost convenient for scripts).</p>
7841cb0ef41Sopenharmony_ci<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>
7851cb0ef41Sopenharmony_ci<div class="api_metadata">
7861cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
7871cb0ef41Sopenharmony_ci<table>
7881cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
7891cb0ef41Sopenharmony_ci<tr><td>v12.0.0, v10.17.0</td>
7901cb0ef41Sopenharmony_ci<td><p>Added the <code>origin</code> argument.</p></td></tr>
7911cb0ef41Sopenharmony_ci<tr><td>v0.1.18</td>
7921cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.18</span></p></td></tr>
7931cb0ef41Sopenharmony_ci</tbody></table>
7941cb0ef41Sopenharmony_ci</details>
7951cb0ef41Sopenharmony_ci</div>
7961cb0ef41Sopenharmony_ci<ul>
7971cb0ef41Sopenharmony_ci<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>
7981cb0ef41Sopenharmony_ci<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
7991cb0ef41Sopenharmony_cirejection or from a synchronous error. Can either be <code>'uncaughtException'</code> or
8001cb0ef41Sopenharmony_ci<code>'unhandledRejection'</code>. The latter is used when an exception happens in a
8011cb0ef41Sopenharmony_ci<code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and
8021cb0ef41Sopenharmony_ci<a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the
8031cb0ef41Sopenharmony_cidefault) and the rejection is not handled, or when a rejection happens during
8041cb0ef41Sopenharmony_cithe command line entry point's ES module static loading phase.</li>
8051cb0ef41Sopenharmony_ci</ul>
8061cb0ef41Sopenharmony_ci<p>The <code>'uncaughtException'</code> event is emitted when an uncaught JavaScript
8071cb0ef41Sopenharmony_ciexception bubbles all the way back to the event loop. By default, Node.js
8081cb0ef41Sopenharmony_cihandles such exceptions by printing the stack trace to <code>stderr</code> and exiting
8091cb0ef41Sopenharmony_ciwith code 1, overriding any previously set <a href="#processexitcode_1"><code>process.exitCode</code></a>.
8101cb0ef41Sopenharmony_ciAdding a handler for the <code>'uncaughtException'</code> event overrides this default
8111cb0ef41Sopenharmony_cibehavior. Alternatively, change the <a href="#processexitcode_1"><code>process.exitCode</code></a> in the
8121cb0ef41Sopenharmony_ci<code>'uncaughtException'</code> handler which will result in the process exiting with the
8131cb0ef41Sopenharmony_ciprovided exit code. Otherwise, in the presence of such handler the process will
8141cb0ef41Sopenharmony_ciexit with 0.</p>
8151cb0ef41Sopenharmony_ci
8161cb0ef41Sopenharmony_ci<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>;
8171cb0ef41Sopenharmony_ci
8181cb0ef41Sopenharmony_ciprocess.<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> {
8191cb0ef41Sopenharmony_ci  fs.<span class="hljs-title function_">writeSync</span>(
8201cb0ef41Sopenharmony_ci    process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>,
8211cb0ef41Sopenharmony_ci    <span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> +
8221cb0ef41Sopenharmony_ci    <span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>`</span>,
8231cb0ef41Sopenharmony_ci  );
8241cb0ef41Sopenharmony_ci});
8251cb0ef41Sopenharmony_ci
8261cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
8271cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>);
8281cb0ef41Sopenharmony_ci}, <span class="hljs-number">500</span>);
8291cb0ef41Sopenharmony_ci
8301cb0ef41Sopenharmony_ci<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
8311cb0ef41Sopenharmony_ci<span class="hljs-title function_">nonexistentFunc</span>();
8321cb0ef41Sopenharmony_ci<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>);
8331cb0ef41Sopenharmony_ci
8341cb0ef41Sopenharmony_ciprocess.<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> {
8351cb0ef41Sopenharmony_ci  fs.<span class="hljs-title function_">writeSync</span>(
8361cb0ef41Sopenharmony_ci    process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>,
8371cb0ef41Sopenharmony_ci    <span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> +
8381cb0ef41Sopenharmony_ci    <span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>`</span>,
8391cb0ef41Sopenharmony_ci  );
8401cb0ef41Sopenharmony_ci});
8411cb0ef41Sopenharmony_ci
8421cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
8431cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>);
8441cb0ef41Sopenharmony_ci}, <span class="hljs-number">500</span>);
8451cb0ef41Sopenharmony_ci
8461cb0ef41Sopenharmony_ci<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
8471cb0ef41Sopenharmony_ci<span class="hljs-title function_">nonexistentFunc</span>();
8481cb0ef41Sopenharmony_ci<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>
8491cb0ef41Sopenharmony_ci<p>It is possible to monitor <code>'uncaughtException'</code> events without overriding the
8501cb0ef41Sopenharmony_cidefault behavior to exit the process by installing a
8511cb0ef41Sopenharmony_ci<code>'uncaughtExceptionMonitor'</code> listener.</p>
8521cb0ef41Sopenharmony_ci<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>
8531cb0ef41Sopenharmony_ci<p><code>'uncaughtException'</code> is a crude mechanism for exception handling
8541cb0ef41Sopenharmony_ciintended to be used only as a last resort. The event <em>should not</em> be used as
8551cb0ef41Sopenharmony_cian equivalent to <code>On Error Resume Next</code>. Unhandled exceptions inherently mean
8561cb0ef41Sopenharmony_cithat an application is in an undefined state. Attempting to resume application
8571cb0ef41Sopenharmony_cicode without properly recovering from the exception can cause additional
8581cb0ef41Sopenharmony_ciunforeseen and unpredictable issues.</p>
8591cb0ef41Sopenharmony_ci<p>Exceptions thrown from within the event handler will not be caught. Instead the
8601cb0ef41Sopenharmony_ciprocess will exit with a non-zero exit code and the stack trace will be printed.
8611cb0ef41Sopenharmony_ciThis is to avoid infinite recursion.</p>
8621cb0ef41Sopenharmony_ci<p>Attempting to resume normally after an uncaught exception can be similar to
8631cb0ef41Sopenharmony_cipulling out the power cord when upgrading a computer. Nine out of ten
8641cb0ef41Sopenharmony_citimes, nothing happens. But the tenth time, the system becomes corrupted.</p>
8651cb0ef41Sopenharmony_ci<p>The correct use of <code>'uncaughtException'</code> is to perform synchronous cleanup
8661cb0ef41Sopenharmony_ciof allocated resources (e.g. file descriptors, handles, etc) before shutting
8671cb0ef41Sopenharmony_cidown the process. <strong>It is not safe to resume normal operation after
8681cb0ef41Sopenharmony_ci<code>'uncaughtException'</code>.</strong></p>
8691cb0ef41Sopenharmony_ci<p>To restart a crashed application in a more reliable way, whether
8701cb0ef41Sopenharmony_ci<code>'uncaughtException'</code> is emitted or not, an external monitor should be employed
8711cb0ef41Sopenharmony_ciin a separate process to detect application failures and recover or restart as
8721cb0ef41Sopenharmony_cineeded.</p>
8731cb0ef41Sopenharmony_ci<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>
8741cb0ef41Sopenharmony_ci<div class="api_metadata">
8751cb0ef41Sopenharmony_ci<span>Added in: v13.7.0, v12.17.0</span>
8761cb0ef41Sopenharmony_ci</div>
8771cb0ef41Sopenharmony_ci<ul>
8781cb0ef41Sopenharmony_ci<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>
8791cb0ef41Sopenharmony_ci<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
8801cb0ef41Sopenharmony_cirejection or from synchronous errors. Can either be <code>'uncaughtException'</code> or
8811cb0ef41Sopenharmony_ci<code>'unhandledRejection'</code>. The latter is used when an exception happens in a
8821cb0ef41Sopenharmony_ci<code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and
8831cb0ef41Sopenharmony_ci<a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the
8841cb0ef41Sopenharmony_cidefault) and the rejection is not handled, or when a rejection happens during
8851cb0ef41Sopenharmony_cithe command line entry point's ES module static loading phase.</li>
8861cb0ef41Sopenharmony_ci</ul>
8871cb0ef41Sopenharmony_ci<p>The <code>'uncaughtExceptionMonitor'</code> event is emitted before an
8881cb0ef41Sopenharmony_ci<code>'uncaughtException'</code> event is emitted or a hook installed via
8891cb0ef41Sopenharmony_ci<a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a> is called.</p>
8901cb0ef41Sopenharmony_ci<p>Installing an <code>'uncaughtExceptionMonitor'</code> listener does not change the behavior
8911cb0ef41Sopenharmony_cionce an <code>'uncaughtException'</code> event is emitted. The process will
8921cb0ef41Sopenharmony_cistill crash if no <code>'uncaughtException'</code> listener is installed.</p>
8931cb0ef41Sopenharmony_ci
8941cb0ef41Sopenharmony_ci<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>;
8951cb0ef41Sopenharmony_ci
8961cb0ef41Sopenharmony_ciprocess.<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> {
8971cb0ef41Sopenharmony_ci  <span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin);
8981cb0ef41Sopenharmony_ci});
8991cb0ef41Sopenharmony_ci
9001cb0ef41Sopenharmony_ci<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
9011cb0ef41Sopenharmony_ci<span class="hljs-title function_">nonexistentFunc</span>();
9021cb0ef41Sopenharmony_ci<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>);
9031cb0ef41Sopenharmony_ci
9041cb0ef41Sopenharmony_ciprocess.<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> {
9051cb0ef41Sopenharmony_ci  <span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin);
9061cb0ef41Sopenharmony_ci});
9071cb0ef41Sopenharmony_ci
9081cb0ef41Sopenharmony_ci<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
9091cb0ef41Sopenharmony_ci<span class="hljs-title function_">nonexistentFunc</span>();
9101cb0ef41Sopenharmony_ci<span class="hljs-comment">// Still crashes Node.js</span></code><button class="copy-button">copy</button></pre>
9111cb0ef41Sopenharmony_ci<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>
9121cb0ef41Sopenharmony_ci<div class="api_metadata">
9131cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9141cb0ef41Sopenharmony_ci<table>
9151cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9161cb0ef41Sopenharmony_ci<tr><td>v7.0.0</td>
9171cb0ef41Sopenharmony_ci<td><p>Not handling <code>Promise</code> rejections is deprecated.</p></td></tr>
9181cb0ef41Sopenharmony_ci<tr><td>v6.6.0</td>
9191cb0ef41Sopenharmony_ci<td><p>Unhandled <code>Promise</code> rejections will now emit a process warning.</p></td></tr>
9201cb0ef41Sopenharmony_ci<tr><td>v1.4.1</td>
9211cb0ef41Sopenharmony_ci<td><p><span>Added in: v1.4.1</span></p></td></tr>
9221cb0ef41Sopenharmony_ci</tbody></table>
9231cb0ef41Sopenharmony_ci</details>
9241cb0ef41Sopenharmony_ci</div>
9251cb0ef41Sopenharmony_ci<ul>
9261cb0ef41Sopenharmony_ci<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
9271cb0ef41Sopenharmony_ci(typically an <a href="errors.html#class-error"><code>Error</code></a> object).</li>
9281cb0ef41Sopenharmony_ci<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>
9291cb0ef41Sopenharmony_ci</ul>
9301cb0ef41Sopenharmony_ci<p>The <code>'unhandledRejection'</code> event is emitted whenever a <code>Promise</code> is rejected and
9311cb0ef41Sopenharmony_cino error handler is attached to the promise within a turn of the event loop.
9321cb0ef41Sopenharmony_ciWhen programming with Promises, exceptions are encapsulated as "rejected
9331cb0ef41Sopenharmony_cipromises". 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
9341cb0ef41Sopenharmony_ciare propagated through a <code>Promise</code> chain. The <code>'unhandledRejection'</code> event is
9351cb0ef41Sopenharmony_ciuseful for detecting and keeping track of promises that were rejected whose
9361cb0ef41Sopenharmony_cirejections have not yet been handled.</p>
9371cb0ef41Sopenharmony_ci
9381cb0ef41Sopenharmony_ci<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>;
9391cb0ef41Sopenharmony_ci
9401cb0ef41Sopenharmony_ciprocess.<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> {
9411cb0ef41Sopenharmony_ci  <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);
9421cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span>
9431cb0ef41Sopenharmony_ci});
9441cb0ef41Sopenharmony_ci
9451cb0ef41Sopenharmony_cisomePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
9461cb0ef41Sopenharmony_ci  <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>
9471cb0ef41Sopenharmony_ci}); <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>);
9481cb0ef41Sopenharmony_ci
9491cb0ef41Sopenharmony_ciprocess.<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> {
9501cb0ef41Sopenharmony_ci  <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);
9511cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span>
9521cb0ef41Sopenharmony_ci});
9531cb0ef41Sopenharmony_ci
9541cb0ef41Sopenharmony_cisomePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
9551cb0ef41Sopenharmony_ci  <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>
9561cb0ef41Sopenharmony_ci}); <span class="hljs-comment">// No `.catch()` or `.then()`</span></code><button class="copy-button">copy</button></pre>
9571cb0ef41Sopenharmony_ci<p>The following will also trigger the <code>'unhandledRejection'</code> event to be
9581cb0ef41Sopenharmony_ciemitted:</p>
9591cb0ef41Sopenharmony_ci
9601cb0ef41Sopenharmony_ci<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>;
9611cb0ef41Sopenharmony_ci
9621cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) {
9631cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Initially set the loaded status to a rejected promise</span>
9641cb0ef41Sopenharmony_ci  <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>));
9651cb0ef41Sopenharmony_ci}
9661cb0ef41Sopenharmony_ci
9671cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>();
9681cb0ef41Sopenharmony_ci<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>);
9691cb0ef41Sopenharmony_ci
9701cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) {
9711cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Initially set the loaded status to a rejected promise</span>
9721cb0ef41Sopenharmony_ci  <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>));
9731cb0ef41Sopenharmony_ci}
9741cb0ef41Sopenharmony_ci
9751cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>();
9761cb0ef41Sopenharmony_ci<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>
9771cb0ef41Sopenharmony_ci<p>In this example case, it is possible to track the rejection as a developer error
9781cb0ef41Sopenharmony_cias would typically be the case for other <code>'unhandledRejection'</code> events. To
9791cb0ef41Sopenharmony_ciaddress such failures, a non-operational
9801cb0ef41Sopenharmony_ci<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
9811cb0ef41Sopenharmony_ci<code>resource.loaded</code>, which would prevent the <code>'unhandledRejection'</code> event from
9821cb0ef41Sopenharmony_cibeing emitted.</p>
9831cb0ef41Sopenharmony_ci<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>
9841cb0ef41Sopenharmony_ci<div class="api_metadata">
9851cb0ef41Sopenharmony_ci<span>Added in: v6.0.0</span>
9861cb0ef41Sopenharmony_ci</div>
9871cb0ef41Sopenharmony_ci<ul>
9881cb0ef41Sopenharmony_ci<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:
9891cb0ef41Sopenharmony_ci<ul>
9901cb0ef41Sopenharmony_ci<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>
9911cb0ef41Sopenharmony_ci<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>
9921cb0ef41Sopenharmony_ci<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
9931cb0ef41Sopenharmony_ciwas issued.</li>
9941cb0ef41Sopenharmony_ci</ul>
9951cb0ef41Sopenharmony_ci</li>
9961cb0ef41Sopenharmony_ci</ul>
9971cb0ef41Sopenharmony_ci<p>The <code>'warning'</code> event is emitted whenever Node.js emits a process warning.</p>
9981cb0ef41Sopenharmony_ci<p>A process warning is similar to an error in that it describes exceptional
9991cb0ef41Sopenharmony_ciconditions that are being brought to the user's attention. However, warnings
10001cb0ef41Sopenharmony_ciare not part of the normal Node.js and JavaScript error handling flow.
10011cb0ef41Sopenharmony_ciNode.js can emit warnings whenever it detects bad coding practices that could
10021cb0ef41Sopenharmony_cilead to sub-optimal application performance, bugs, or security vulnerabilities.</p>
10031cb0ef41Sopenharmony_ci
10041cb0ef41Sopenharmony_ci<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>;
10051cb0ef41Sopenharmony_ci
10061cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
10071cb0ef41Sopenharmony_ci  <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>
10081cb0ef41Sopenharmony_ci  <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>
10091cb0ef41Sopenharmony_ci  <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>
10101cb0ef41Sopenharmony_ci});</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>);
10111cb0ef41Sopenharmony_ci
10121cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
10131cb0ef41Sopenharmony_ci  <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>
10141cb0ef41Sopenharmony_ci  <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>
10151cb0ef41Sopenharmony_ci  <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>
10161cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
10171cb0ef41Sopenharmony_ci<p>By default, Node.js will print process warnings to <code>stderr</code>. The <code>--no-warnings</code>
10181cb0ef41Sopenharmony_cicommand-line option can be used to suppress the default console output but the
10191cb0ef41Sopenharmony_ci<code>'warning'</code> event will still be emitted by the <code>process</code> object.</p>
10201cb0ef41Sopenharmony_ci<p>The following example illustrates the warning that is printed to <code>stderr</code> when
10211cb0ef41Sopenharmony_citoo many listeners have been added to an event:</p>
10221cb0ef41Sopenharmony_ci<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span>
10231cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
10241cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
10251cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
10261cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">(node:38638) MaxListenersExceededWarning: Possible EventEmitter memory leak</span>
10271cb0ef41Sopenharmony_cidetected. 2 foo listeners added. Use emitter.setMaxListeners() to increase limit</code> <button class="copy-button">copy</button></pre>
10281cb0ef41Sopenharmony_ci<p>In contrast, the following example turns off the default warning output and
10291cb0ef41Sopenharmony_ciadds a custom handler to the <code>'warning'</code> event:</p>
10301cb0ef41Sopenharmony_ci<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node --no-warnings</span>
10311cb0ef41Sopenharmony_ci<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>
10321cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
10331cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
10341cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
10351cb0ef41Sopenharmony_ci<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>
10361cb0ef41Sopenharmony_ci<p>The <code>--trace-warnings</code> command-line option can be used to have the default
10371cb0ef41Sopenharmony_ciconsole output for warnings include the full stack trace of the warning.</p>
10381cb0ef41Sopenharmony_ci<p>Launching Node.js using the <code>--throw-deprecation</code> command-line flag will
10391cb0ef41Sopenharmony_cicause custom deprecation warnings to be thrown as exceptions.</p>
10401cb0ef41Sopenharmony_ci<p>Using the <code>--trace-deprecation</code> command-line flag will cause the custom
10411cb0ef41Sopenharmony_cideprecation to be printed to <code>stderr</code> along with the stack trace.</p>
10421cb0ef41Sopenharmony_ci<p>Using the <code>--no-deprecation</code> command-line flag will suppress all reporting
10431cb0ef41Sopenharmony_ciof the custom deprecation.</p>
10441cb0ef41Sopenharmony_ci<p>The <code>*-deprecation</code> command-line flags only affect warnings that use the name
10451cb0ef41Sopenharmony_ci<code>'DeprecationWarning'</code>.</p>
10461cb0ef41Sopenharmony_ci<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>
10471cb0ef41Sopenharmony_ci<div class="api_metadata">
10481cb0ef41Sopenharmony_ci<span>Added in: v16.2.0, v14.18.0</span>
10491cb0ef41Sopenharmony_ci</div>
10501cb0ef41Sopenharmony_ci<ul>
10511cb0ef41Sopenharmony_ci<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>
10521cb0ef41Sopenharmony_ci</ul>
10531cb0ef41Sopenharmony_ci<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>
10541cb0ef41Sopenharmony_ci<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>
10551cb0ef41Sopenharmony_ci<p>See the <a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning()</code></a> method for issuing
10561cb0ef41Sopenharmony_cicustom or application-specific warnings.</p>
10571cb0ef41Sopenharmony_ci<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>
10581cb0ef41Sopenharmony_ci<p>There are no strict guidelines for warning types (as identified by the <code>name</code>
10591cb0ef41Sopenharmony_ciproperty) emitted by Node.js. New types of warnings can be added at any time.
10601cb0ef41Sopenharmony_ciA few of the warning types that are most common include:</p>
10611cb0ef41Sopenharmony_ci<ul>
10621cb0ef41Sopenharmony_ci<li><code>'DeprecationWarning'</code> - Indicates use of a deprecated Node.js API or feature.
10631cb0ef41Sopenharmony_ciSuch warnings must include a <code>'code'</code> property identifying the
10641cb0ef41Sopenharmony_ci<a href="deprecations.html">deprecation code</a>.</li>
10651cb0ef41Sopenharmony_ci<li><code>'ExperimentalWarning'</code> - Indicates use of an experimental Node.js API or
10661cb0ef41Sopenharmony_cifeature. Such features must be used with caution as they may change at any
10671cb0ef41Sopenharmony_citime and are not subject to the same strict semantic-versioning and long-term
10681cb0ef41Sopenharmony_cisupport policies as supported features.</li>
10691cb0ef41Sopenharmony_ci<li><code>'MaxListenersExceededWarning'</code> - Indicates that too many listeners for a
10701cb0ef41Sopenharmony_cigiven event have been registered on either an <code>EventEmitter</code> or <code>EventTarget</code>.
10711cb0ef41Sopenharmony_ciThis is often an indication of a memory leak.</li>
10721cb0ef41Sopenharmony_ci<li><code>'TimeoutOverflowWarning'</code> - Indicates that a numeric value that cannot fit
10731cb0ef41Sopenharmony_ciwithin a 32-bit signed integer has been provided to either the <code>setTimeout()</code>
10741cb0ef41Sopenharmony_cior <code>setInterval()</code> functions.</li>
10751cb0ef41Sopenharmony_ci<li><code>'UnsupportedWarning'</code> - Indicates use of an unsupported option or feature
10761cb0ef41Sopenharmony_cithat will be ignored rather than treated as an error. One example is use of
10771cb0ef41Sopenharmony_cithe HTTP response status message when using the HTTP/2 compatibility API.</li>
10781cb0ef41Sopenharmony_ci</ul>
10791cb0ef41Sopenharmony_ci<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>
10801cb0ef41Sopenharmony_ci
10811cb0ef41Sopenharmony_ci
10821cb0ef41Sopenharmony_ci<p>Signal events will be emitted when the Node.js process receives a signal. Please
10831cb0ef41Sopenharmony_cirefer 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
10841cb0ef41Sopenharmony_ci<code>'SIGINT'</code>, <code>'SIGHUP'</code>, etc.</p>
10851cb0ef41Sopenharmony_ci<p>Signals are not available on <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
10861cb0ef41Sopenharmony_ci<p>The signal handler will receive the signal's name (<code>'SIGINT'</code>,
10871cb0ef41Sopenharmony_ci<code>'SIGTERM'</code>, etc.) as the first argument.</p>
10881cb0ef41Sopenharmony_ci<p>The name of each event will be the uppercase common name for the signal (e.g.
10891cb0ef41Sopenharmony_ci<code>'SIGINT'</code> for <code>SIGINT</code> signals).</p>
10901cb0ef41Sopenharmony_ci
10911cb0ef41Sopenharmony_ci<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>;
10921cb0ef41Sopenharmony_ci
10931cb0ef41Sopenharmony_ci<span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span>
10941cb0ef41Sopenharmony_ciprocess.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>();
10951cb0ef41Sopenharmony_ci
10961cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> {
10971cb0ef41Sopenharmony_ci  <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>);
10981cb0ef41Sopenharmony_ci});
10991cb0ef41Sopenharmony_ci
11001cb0ef41Sopenharmony_ci<span class="hljs-comment">// Using a single function to handle multiple signals</span>
11011cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) {
11021cb0ef41Sopenharmony_ci  <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>);
11031cb0ef41Sopenharmony_ci}
11041cb0ef41Sopenharmony_ci
11051cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle);
11061cb0ef41Sopenharmony_ciprocess.<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>);
11071cb0ef41Sopenharmony_ci
11081cb0ef41Sopenharmony_ci<span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span>
11091cb0ef41Sopenharmony_ciprocess.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>();
11101cb0ef41Sopenharmony_ci
11111cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> {
11121cb0ef41Sopenharmony_ci  <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>);
11131cb0ef41Sopenharmony_ci});
11141cb0ef41Sopenharmony_ci
11151cb0ef41Sopenharmony_ci<span class="hljs-comment">// Using a single function to handle multiple signals</span>
11161cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) {
11171cb0ef41Sopenharmony_ci  <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>);
11181cb0ef41Sopenharmony_ci}
11191cb0ef41Sopenharmony_ci
11201cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle);
11211cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGTERM'</span>, handle);</code><button class="copy-button">copy</button></pre>
11221cb0ef41Sopenharmony_ci<ul>
11231cb0ef41Sopenharmony_ci<li><code>'SIGUSR1'</code> is reserved by Node.js to start the <a href="debugger.html">debugger</a>. It's possible to
11241cb0ef41Sopenharmony_ciinstall a listener but doing so might interfere with the debugger.</li>
11251cb0ef41Sopenharmony_ci<li><code>'SIGTERM'</code> and <code>'SIGINT'</code> have default handlers on non-Windows platforms that
11261cb0ef41Sopenharmony_cireset the terminal mode before exiting with code <code>128 + signal number</code>. If one
11271cb0ef41Sopenharmony_ciof these signals has a listener installed, its default behavior will be
11281cb0ef41Sopenharmony_ciremoved (Node.js will no longer exit).</li>
11291cb0ef41Sopenharmony_ci<li><code>'SIGPIPE'</code> is ignored by default. It can have a listener installed.</li>
11301cb0ef41Sopenharmony_ci<li><code>'SIGHUP'</code> is generated on Windows when the console window is closed, and on
11311cb0ef41Sopenharmony_ciother 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
11321cb0ef41Sopenharmony_cilistener installed, however Node.js will be unconditionally terminated by
11331cb0ef41Sopenharmony_ciWindows about 10 seconds later. On non-Windows platforms, the default
11341cb0ef41Sopenharmony_cibehavior of <code>SIGHUP</code> is to terminate Node.js, but once a listener has been
11351cb0ef41Sopenharmony_ciinstalled its default behavior will be removed.</li>
11361cb0ef41Sopenharmony_ci<li><code>'SIGTERM'</code> is not supported on Windows, it can be listened on.</li>
11371cb0ef41Sopenharmony_ci<li><code>'SIGINT'</code> from the terminal is supported on all platforms, and can usually be
11381cb0ef41Sopenharmony_cigenerated with <kbd>Ctrl</kbd>+<kbd>C</kbd> (though this may be configurable).
11391cb0ef41Sopenharmony_ciIt is not generated when <a href="tty.html#readstreamsetrawmodemode">terminal raw mode</a> is enabled
11401cb0ef41Sopenharmony_ciand <kbd>Ctrl</kbd>+<kbd>C</kbd> is used.</li>
11411cb0ef41Sopenharmony_ci<li><code>'SIGBREAK'</code> is delivered on Windows when <kbd>Ctrl</kbd>+<kbd>Break</kbd> is
11421cb0ef41Sopenharmony_cipressed. On non-Windows platforms, it can be listened on, but there is no way
11431cb0ef41Sopenharmony_cito send or generate it.</li>
11441cb0ef41Sopenharmony_ci<li><code>'SIGWINCH'</code> is delivered when the console has been resized. On Windows, this
11451cb0ef41Sopenharmony_ciwill only happen on write to the console when the cursor is being moved, or
11461cb0ef41Sopenharmony_ciwhen a readable tty is used in raw mode.</li>
11471cb0ef41Sopenharmony_ci<li><code>'SIGKILL'</code> cannot have a listener installed, it will unconditionally
11481cb0ef41Sopenharmony_citerminate Node.js on all platforms.</li>
11491cb0ef41Sopenharmony_ci<li><code>'SIGSTOP'</code> cannot have a listener installed.</li>
11501cb0ef41Sopenharmony_ci<li><code>'SIGBUS'</code>, <code>'SIGFPE'</code>, <code>'SIGSEGV'</code>, and <code>'SIGILL'</code>, when not raised
11511cb0ef41Sopenharmony_ciartificially 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
11521cb0ef41Sopenharmony_ciwhich it is not safe to call JS listeners. Doing so might cause the process
11531cb0ef41Sopenharmony_cito stop responding.</li>
11541cb0ef41Sopenharmony_ci<li><code>0</code> can be sent to test for the existence of a process, it has no effect if
11551cb0ef41Sopenharmony_cithe process exists, but will throw an error if the process does not exist.</li>
11561cb0ef41Sopenharmony_ci</ul>
11571cb0ef41Sopenharmony_ci<p>Windows does not support signals so has no equivalent to termination by signal,
11581cb0ef41Sopenharmony_cibut Node.js offers some emulation with <a href="#processkillpid-signal"><code>process.kill()</code></a>, and
11591cb0ef41Sopenharmony_ci<a href="child_process.html#subprocesskillsignal"><code>subprocess.kill()</code></a>:</p>
11601cb0ef41Sopenharmony_ci<ul>
11611cb0ef41Sopenharmony_ci<li>Sending <code>SIGINT</code>, <code>SIGTERM</code>, and <code>SIGKILL</code> will cause the unconditional
11621cb0ef41Sopenharmony_citermination of the target process, and afterwards, subprocess will report that
11631cb0ef41Sopenharmony_cithe process was terminated by signal.</li>
11641cb0ef41Sopenharmony_ci<li>Sending signal <code>0</code> can be used as a platform independent way to test for the
11651cb0ef41Sopenharmony_ciexistence of a process.</li>
11661cb0ef41Sopenharmony_ci</ul>
11671cb0ef41Sopenharmony_ci</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>
11681cb0ef41Sopenharmony_ci<div class="api_metadata">
11691cb0ef41Sopenharmony_ci<span>Added in: v0.7.0</span>
11701cb0ef41Sopenharmony_ci</div>
11711cb0ef41Sopenharmony_ci<p>The <code>process.abort()</code> method causes the Node.js process to exit immediately and
11721cb0ef41Sopenharmony_cigenerate a core file.</p>
11731cb0ef41Sopenharmony_ci<p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
11741cb0ef41Sopenharmony_ci</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>
11751cb0ef41Sopenharmony_ci<div class="api_metadata">
11761cb0ef41Sopenharmony_ci<span>Added in: v10.10.0</span>
11771cb0ef41Sopenharmony_ci</div>
11781cb0ef41Sopenharmony_ci<ul>
11791cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set" class="type">&#x3C;Set></a></li>
11801cb0ef41Sopenharmony_ci</ul>
11811cb0ef41Sopenharmony_ci<p>The <code>process.allowedNodeEnvironmentFlags</code> property is a special,
11821cb0ef41Sopenharmony_ciread-only <code>Set</code> of flags allowable within the <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a>
11831cb0ef41Sopenharmony_cienvironment variable.</p>
11841cb0ef41Sopenharmony_ci<p><code>process.allowedNodeEnvironmentFlags</code> extends <code>Set</code>, but overrides
11851cb0ef41Sopenharmony_ci<code>Set.prototype.has</code> to recognize several different possible flag
11861cb0ef41Sopenharmony_cirepresentations. <code>process.allowedNodeEnvironmentFlags.has()</code> will
11871cb0ef41Sopenharmony_cireturn <code>true</code> in the following cases:</p>
11881cb0ef41Sopenharmony_ci<ul>
11891cb0ef41Sopenharmony_ci<li>Flags may omit leading single (<code>-</code>) or double (<code>--</code>) dashes; e.g.,
11901cb0ef41Sopenharmony_ci<code>inspect-brk</code> for <code>--inspect-brk</code>, or <code>r</code> for <code>-r</code>.</li>
11911cb0ef41Sopenharmony_ci<li>Flags passed through to V8 (as listed in <code>--v8-options</code>) may replace
11921cb0ef41Sopenharmony_cione or more <em>non-leading</em> dashes for an underscore, or vice-versa;
11931cb0ef41Sopenharmony_cie.g., <code>--perf_basic_prof</code>, <code>--perf-basic-prof</code>, <code>--perf_basic-prof</code>,
11941cb0ef41Sopenharmony_cietc.</li>
11951cb0ef41Sopenharmony_ci<li>Flags may contain one or more equals (<code>=</code>) characters; all
11961cb0ef41Sopenharmony_cicharacters after and including the first equals will be ignored;
11971cb0ef41Sopenharmony_cie.g., <code>--stack-trace-limit=100</code>.</li>
11981cb0ef41Sopenharmony_ci<li>Flags <em>must</em> be allowable within <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a>.</li>
11991cb0ef41Sopenharmony_ci</ul>
12001cb0ef41Sopenharmony_ci<p>When iterating over <code>process.allowedNodeEnvironmentFlags</code>, flags will
12011cb0ef41Sopenharmony_ciappear only <em>once</em>; each will begin with one or more dashes. Flags
12021cb0ef41Sopenharmony_cipassed through to V8 will contain underscores instead of non-leading
12031cb0ef41Sopenharmony_cidashes:</p>
12041cb0ef41Sopenharmony_ci
12051cb0ef41Sopenharmony_ci<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>;
12061cb0ef41Sopenharmony_ci
12071cb0ef41Sopenharmony_ciallowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> {
12081cb0ef41Sopenharmony_ci  <span class="hljs-comment">// -r</span>
12091cb0ef41Sopenharmony_ci  <span class="hljs-comment">// --inspect-brk</span>
12101cb0ef41Sopenharmony_ci  <span class="hljs-comment">// --abort_on_uncaught_exception</span>
12111cb0ef41Sopenharmony_ci  <span class="hljs-comment">// ...</span>
12121cb0ef41Sopenharmony_ci});</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>);
12131cb0ef41Sopenharmony_ci
12141cb0ef41Sopenharmony_ciallowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> {
12151cb0ef41Sopenharmony_ci  <span class="hljs-comment">// -r</span>
12161cb0ef41Sopenharmony_ci  <span class="hljs-comment">// --inspect-brk</span>
12171cb0ef41Sopenharmony_ci  <span class="hljs-comment">// --abort_on_uncaught_exception</span>
12181cb0ef41Sopenharmony_ci  <span class="hljs-comment">// ...</span>
12191cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
12201cb0ef41Sopenharmony_ci<p>The methods <code>add()</code>, <code>clear()</code>, and <code>delete()</code> of
12211cb0ef41Sopenharmony_ci<code>process.allowedNodeEnvironmentFlags</code> do nothing, and will fail
12221cb0ef41Sopenharmony_cisilently.</p>
12231cb0ef41Sopenharmony_ci<p>If Node.js was compiled <em>without</em> <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a> support (shown in
12241cb0ef41Sopenharmony_ci<a href="#processconfig"><code>process.config</code></a>), <code>process.allowedNodeEnvironmentFlags</code> will
12251cb0ef41Sopenharmony_cicontain what <em>would have</em> been allowable.</p>
12261cb0ef41Sopenharmony_ci</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>
12271cb0ef41Sopenharmony_ci<div class="api_metadata">
12281cb0ef41Sopenharmony_ci<span>Added in: v0.5.0</span>
12291cb0ef41Sopenharmony_ci</div>
12301cb0ef41Sopenharmony_ci<ul>
12311cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12321cb0ef41Sopenharmony_ci</ul>
12331cb0ef41Sopenharmony_ci<p>The operating system CPU architecture for which the Node.js binary was compiled.
12341cb0ef41Sopenharmony_ciPossible values are: <code>'arm'</code>, <code>'arm64'</code>, <code>'ia32'</code>, <code>'mips'</code>,<code>'mipsel'</code>, <code>'ppc'</code>,
12351cb0ef41Sopenharmony_ci<code>'ppc64'</code>, <code>'s390'</code>, <code>'s390x'</code>, and <code>'x64'</code>.</p>
12361cb0ef41Sopenharmony_ci
12371cb0ef41Sopenharmony_ci<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>;
12381cb0ef41Sopenharmony_ci
12391cb0ef41Sopenharmony_ci<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>);
12401cb0ef41Sopenharmony_ci
12411cb0ef41Sopenharmony_ci<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>
12421cb0ef41Sopenharmony_ci</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>
12431cb0ef41Sopenharmony_ci<div class="api_metadata">
12441cb0ef41Sopenharmony_ci<span>Added in: v0.1.27</span>
12451cb0ef41Sopenharmony_ci</div>
12461cb0ef41Sopenharmony_ci<ul>
12471cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
12481cb0ef41Sopenharmony_ci</ul>
12491cb0ef41Sopenharmony_ci<p>The <code>process.argv</code> property returns an array containing the command-line
12501cb0ef41Sopenharmony_ciarguments passed when the Node.js process was launched. The first element will
12511cb0ef41Sopenharmony_cibe <a href="#processexecpath"><code>process.execPath</code></a>. See <code>process.argv0</code> if access to the original value
12521cb0ef41Sopenharmony_ciof <code>argv[0]</code> is needed. The second element will be the path to the JavaScript
12531cb0ef41Sopenharmony_cifile being executed. The remaining elements will be any additional command-line
12541cb0ef41Sopenharmony_ciarguments.</p>
12551cb0ef41Sopenharmony_ci<p>For example, assuming the following script for <code>process-args.js</code>:</p>
12561cb0ef41Sopenharmony_ci
12571cb0ef41Sopenharmony_ci<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>;
12581cb0ef41Sopenharmony_ci
12591cb0ef41Sopenharmony_ci<span class="hljs-comment">// print process.argv</span>
12601cb0ef41Sopenharmony_ciargv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> {
12611cb0ef41Sopenharmony_ci  <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>);
12621cb0ef41Sopenharmony_ci});</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>);
12631cb0ef41Sopenharmony_ci
12641cb0ef41Sopenharmony_ci<span class="hljs-comment">// print process.argv</span>
12651cb0ef41Sopenharmony_ciargv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> {
12661cb0ef41Sopenharmony_ci  <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>);
12671cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
12681cb0ef41Sopenharmony_ci<p>Launching the Node.js process as:</p>
12691cb0ef41Sopenharmony_ci<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>
12701cb0ef41Sopenharmony_ci<p>Would generate the output:</p>
12711cb0ef41Sopenharmony_ci<pre><code class="language-text">0: /usr/local/bin/node
12721cb0ef41Sopenharmony_ci1: /Users/mjr/work/node/process-args.js
12731cb0ef41Sopenharmony_ci2: one
12741cb0ef41Sopenharmony_ci3: two=three
12751cb0ef41Sopenharmony_ci4: four</code> <button class="copy-button">copy</button></pre>
12761cb0ef41Sopenharmony_ci</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>
12771cb0ef41Sopenharmony_ci<div class="api_metadata">
12781cb0ef41Sopenharmony_ci<span>Added in: v6.4.0</span>
12791cb0ef41Sopenharmony_ci</div>
12801cb0ef41Sopenharmony_ci<ul>
12811cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12821cb0ef41Sopenharmony_ci</ul>
12831cb0ef41Sopenharmony_ci<p>The <code>process.argv0</code> property stores a read-only copy of the original value of
12841cb0ef41Sopenharmony_ci<code>argv[0]</code> passed when Node.js starts.</p>
12851cb0ef41Sopenharmony_ci<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>
12861cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv[0]</span>
12871cb0ef41Sopenharmony_ci'/Volumes/code/external/node/out/Release/node'
12881cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv0</span>
12891cb0ef41Sopenharmony_ci'customArgv0'</code> <button class="copy-button">copy</button></pre>
12901cb0ef41Sopenharmony_ci</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>
12911cb0ef41Sopenharmony_ci<div class="api_metadata">
12921cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12931cb0ef41Sopenharmony_ci<table>
12941cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12951cb0ef41Sopenharmony_ci<tr><td>v14.0.0</td>
12961cb0ef41Sopenharmony_ci<td><p>The object no longer accidentally exposes native C++ bindings.</p></td></tr>
12971cb0ef41Sopenharmony_ci<tr><td>v7.1.0</td>
12981cb0ef41Sopenharmony_ci<td><p><span>Added in: v7.1.0</span></p></td></tr>
12991cb0ef41Sopenharmony_ci</tbody></table>
13001cb0ef41Sopenharmony_ci</details>
13011cb0ef41Sopenharmony_ci</div>
13021cb0ef41Sopenharmony_ci<ul>
13031cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
13041cb0ef41Sopenharmony_ci</ul>
13051cb0ef41Sopenharmony_ci<p>If the Node.js process was spawned with an IPC channel (see the
13061cb0ef41Sopenharmony_ci<a href="child_process.html">Child Process</a> documentation), the <code>process.channel</code>
13071cb0ef41Sopenharmony_ciproperty is a reference to the IPC channel. If no IPC channel exists, this
13081cb0ef41Sopenharmony_ciproperty is <code>undefined</code>.</p>
13091cb0ef41Sopenharmony_ci<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>
13101cb0ef41Sopenharmony_ci<div class="api_metadata">
13111cb0ef41Sopenharmony_ci<span>Added in: v7.1.0</span>
13121cb0ef41Sopenharmony_ci</div>
13131cb0ef41Sopenharmony_ci<p>This method makes the IPC channel keep the event loop of the process
13141cb0ef41Sopenharmony_cirunning if <code>.unref()</code> has been called before.</p>
13151cb0ef41Sopenharmony_ci<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
13161cb0ef41Sopenharmony_cilisteners on the <code>process</code> object. However, this method can be used to
13171cb0ef41Sopenharmony_ciexplicitly request a specific behavior.</p>
13181cb0ef41Sopenharmony_ci<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>
13191cb0ef41Sopenharmony_ci<div class="api_metadata">
13201cb0ef41Sopenharmony_ci<span>Added in: v7.1.0</span>
13211cb0ef41Sopenharmony_ci</div>
13221cb0ef41Sopenharmony_ci<p>This method makes the IPC channel not keep the event loop of the process
13231cb0ef41Sopenharmony_cirunning, and lets it finish even while the channel is open.</p>
13241cb0ef41Sopenharmony_ci<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
13251cb0ef41Sopenharmony_cilisteners on the <code>process</code> object. However, this method can be used to
13261cb0ef41Sopenharmony_ciexplicitly request a specific behavior.</p>
13271cb0ef41Sopenharmony_ci</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>
13281cb0ef41Sopenharmony_ci<div class="api_metadata">
13291cb0ef41Sopenharmony_ci<span>Added in: v0.1.17</span>
13301cb0ef41Sopenharmony_ci</div>
13311cb0ef41Sopenharmony_ci<ul>
13321cb0ef41Sopenharmony_ci<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>
13331cb0ef41Sopenharmony_ci</ul>
13341cb0ef41Sopenharmony_ci<p>The <code>process.chdir()</code> method changes the current working directory of the
13351cb0ef41Sopenharmony_ciNode.js process or throws an exception if doing so fails (for instance, if
13361cb0ef41Sopenharmony_cithe specified <code>directory</code> does not exist).</p>
13371cb0ef41Sopenharmony_ci
13381cb0ef41Sopenharmony_ci<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>;
13391cb0ef41Sopenharmony_ci
13401cb0ef41Sopenharmony_ci<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>);
13411cb0ef41Sopenharmony_ci<span class="hljs-keyword">try</span> {
13421cb0ef41Sopenharmony_ci  <span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>);
13431cb0ef41Sopenharmony_ci  <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>);
13441cb0ef41Sopenharmony_ci} <span class="hljs-keyword">catch</span> (err) {
13451cb0ef41Sopenharmony_ci  <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>);
13461cb0ef41Sopenharmony_ci}</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>);
13471cb0ef41Sopenharmony_ci
13481cb0ef41Sopenharmony_ci<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>);
13491cb0ef41Sopenharmony_ci<span class="hljs-keyword">try</span> {
13501cb0ef41Sopenharmony_ci  <span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>);
13511cb0ef41Sopenharmony_ci  <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>);
13521cb0ef41Sopenharmony_ci} <span class="hljs-keyword">catch</span> (err) {
13531cb0ef41Sopenharmony_ci  <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>);
13541cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
13551cb0ef41Sopenharmony_ci<p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
13561cb0ef41Sopenharmony_ci</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>
13571cb0ef41Sopenharmony_ci<div class="api_metadata">
13581cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13591cb0ef41Sopenharmony_ci<table>
13601cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13611cb0ef41Sopenharmony_ci<tr><td>v16.0.0</td>
13621cb0ef41Sopenharmony_ci<td><p>Modifying process.config has been deprecated.</p></td></tr>
13631cb0ef41Sopenharmony_ci<tr><td>v0.7.7</td>
13641cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.7.7</span></p></td></tr>
13651cb0ef41Sopenharmony_ci</tbody></table>
13661cb0ef41Sopenharmony_ci</details>
13671cb0ef41Sopenharmony_ci</div>
13681cb0ef41Sopenharmony_ci<ul>
13691cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
13701cb0ef41Sopenharmony_ci</ul>
13711cb0ef41Sopenharmony_ci<p>The <code>process.config</code> property returns an <code>Object</code> containing the JavaScript
13721cb0ef41Sopenharmony_cirepresentation of the configure options used to compile the current Node.js
13731cb0ef41Sopenharmony_ciexecutable. This is the same as the <code>config.gypi</code> file that was produced when
13741cb0ef41Sopenharmony_cirunning the <code>./configure</code> script.</p>
13751cb0ef41Sopenharmony_ci<p>An example of the possible output looks like:</p>
13761cb0ef41Sopenharmony_ci<!-- eslint-skip -->
13771cb0ef41Sopenharmony_ci<pre><code class="language-js">{
13781cb0ef41Sopenharmony_ci  <span class="hljs-attr">target_defaults</span>:
13791cb0ef41Sopenharmony_ci   { <span class="hljs-attr">cflags</span>: [],
13801cb0ef41Sopenharmony_ci     <span class="hljs-attr">default_configuration</span>: <span class="hljs-string">'Release'</span>,
13811cb0ef41Sopenharmony_ci     <span class="hljs-attr">defines</span>: [],
13821cb0ef41Sopenharmony_ci     <span class="hljs-attr">include_dirs</span>: [],
13831cb0ef41Sopenharmony_ci     <span class="hljs-attr">libraries</span>: [] },
13841cb0ef41Sopenharmony_ci  <span class="hljs-attr">variables</span>:
13851cb0ef41Sopenharmony_ci   {
13861cb0ef41Sopenharmony_ci     <span class="hljs-attr">host_arch</span>: <span class="hljs-string">'x64'</span>,
13871cb0ef41Sopenharmony_ci     <span class="hljs-attr">napi_build_version</span>: <span class="hljs-number">5</span>,
13881cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_install_npm</span>: <span class="hljs-string">'true'</span>,
13891cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_prefix</span>: <span class="hljs-string">''</span>,
13901cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_shared_cares</span>: <span class="hljs-string">'false'</span>,
13911cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_shared_http_parser</span>: <span class="hljs-string">'false'</span>,
13921cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_shared_libuv</span>: <span class="hljs-string">'false'</span>,
13931cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_shared_zlib</span>: <span class="hljs-string">'false'</span>,
13941cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_use_dtrace</span>: <span class="hljs-string">'false'</span>,
13951cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_use_openssl</span>: <span class="hljs-string">'true'</span>,
13961cb0ef41Sopenharmony_ci     <span class="hljs-attr">node_shared_openssl</span>: <span class="hljs-string">'false'</span>,
13971cb0ef41Sopenharmony_ci     <span class="hljs-attr">strict_aliasing</span>: <span class="hljs-string">'true'</span>,
13981cb0ef41Sopenharmony_ci     <span class="hljs-attr">target_arch</span>: <span class="hljs-string">'x64'</span>,
13991cb0ef41Sopenharmony_ci     <span class="hljs-attr">v8_use_snapshot</span>: <span class="hljs-number">1</span>
14001cb0ef41Sopenharmony_ci   }
14011cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
14021cb0ef41Sopenharmony_ci<p>The <code>process.config</code> property is <strong>not</strong> read-only and there are existing
14031cb0ef41Sopenharmony_cimodules in the ecosystem that are known to extend, modify, or entirely replace
14041cb0ef41Sopenharmony_cithe value of <code>process.config</code>.</p>
14051cb0ef41Sopenharmony_ci<p>Modifying the <code>process.config</code> property, or any child-property of the
14061cb0ef41Sopenharmony_ci<code>process.config</code> object has been deprecated. The <code>process.config</code> will be made
14071cb0ef41Sopenharmony_ciread-only in a future release.</p>
14081cb0ef41Sopenharmony_ci</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>
14091cb0ef41Sopenharmony_ci<div class="api_metadata">
14101cb0ef41Sopenharmony_ci<span>Added in: v0.7.2</span>
14111cb0ef41Sopenharmony_ci</div>
14121cb0ef41Sopenharmony_ci<ul>
14131cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
14141cb0ef41Sopenharmony_ci</ul>
14151cb0ef41Sopenharmony_ci<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
14161cb0ef41Sopenharmony_ciand <a href="cluster.html">Cluster</a> documentation), the <code>process.connected</code> property will return
14171cb0ef41Sopenharmony_ci<code>true</code> so long as the IPC channel is connected and will return <code>false</code> after
14181cb0ef41Sopenharmony_ci<code>process.disconnect()</code> is called.</p>
14191cb0ef41Sopenharmony_ci<p>Once <code>process.connected</code> is <code>false</code>, it is no longer possible to send messages
14201cb0ef41Sopenharmony_ciover the IPC channel using <code>process.send()</code>.</p>
14211cb0ef41Sopenharmony_ci</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>
14221cb0ef41Sopenharmony_ci<div class="api_metadata">
14231cb0ef41Sopenharmony_ci<span>Added in: v18.15.0</span>
14241cb0ef41Sopenharmony_ci</div>
14251cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
14261cb0ef41Sopenharmony_ci<ul>
14271cb0ef41Sopenharmony_ci<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>
14281cb0ef41Sopenharmony_ci</ul>
14291cb0ef41Sopenharmony_ci<p>Gets the amount of memory available to the process (in bytes) based on
14301cb0ef41Sopenharmony_cilimits imposed by the OS. If there is no such constraint, or the constraint
14311cb0ef41Sopenharmony_ciis unknown, <code>undefined</code> is returned.</p>
14321cb0ef41Sopenharmony_ci<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
14331cb0ef41Sopenharmony_ciinformation.</p>
14341cb0ef41Sopenharmony_ci</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>
14351cb0ef41Sopenharmony_ci<div class="api_metadata">
14361cb0ef41Sopenharmony_ci<span>Added in: v6.1.0</span>
14371cb0ef41Sopenharmony_ci</div>
14381cb0ef41Sopenharmony_ci<ul>
14391cb0ef41Sopenharmony_ci<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
14401cb0ef41Sopenharmony_ci<code>process.cpuUsage()</code></li>
14411cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
14421cb0ef41Sopenharmony_ci<ul>
14431cb0ef41Sopenharmony_ci<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>
14441cb0ef41Sopenharmony_ci<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>
14451cb0ef41Sopenharmony_ci</ul>
14461cb0ef41Sopenharmony_ci</li>
14471cb0ef41Sopenharmony_ci</ul>
14481cb0ef41Sopenharmony_ci<p>The <code>process.cpuUsage()</code> method returns the user and system CPU time usage of
14491cb0ef41Sopenharmony_cithe current process, in an object with properties <code>user</code> and <code>system</code>, whose
14501cb0ef41Sopenharmony_civalues are microsecond values (millionth of a second). These values measure time
14511cb0ef41Sopenharmony_cispent in user and system code respectively, and may end up being greater than
14521cb0ef41Sopenharmony_ciactual elapsed time if multiple CPU cores are performing work for this process.</p>
14531cb0ef41Sopenharmony_ci<p>The result of a previous call to <code>process.cpuUsage()</code> can be passed as the
14541cb0ef41Sopenharmony_ciargument to the function, to get a diff reading.</p>
14551cb0ef41Sopenharmony_ci
14561cb0ef41Sopenharmony_ci<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>;
14571cb0ef41Sopenharmony_ci
14581cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>();
14591cb0ef41Sopenharmony_ci<span class="hljs-comment">// { user: 38579, system: 6986 }</span>
14601cb0ef41Sopenharmony_ci
14611cb0ef41Sopenharmony_ci<span class="hljs-comment">// spin the CPU for 500 milliseconds</span>
14621cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>();
14631cb0ef41Sopenharmony_ci<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>);
14641cb0ef41Sopenharmony_ci
14651cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage));
14661cb0ef41Sopenharmony_ci<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>);
14671cb0ef41Sopenharmony_ci
14681cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>();
14691cb0ef41Sopenharmony_ci<span class="hljs-comment">// { user: 38579, system: 6986 }</span>
14701cb0ef41Sopenharmony_ci
14711cb0ef41Sopenharmony_ci<span class="hljs-comment">// spin the CPU for 500 milliseconds</span>
14721cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>();
14731cb0ef41Sopenharmony_ci<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>);
14741cb0ef41Sopenharmony_ci
14751cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage));
14761cb0ef41Sopenharmony_ci<span class="hljs-comment">// { user: 514883, system: 11226 }</span></code><button class="copy-button">copy</button></pre>
14771cb0ef41Sopenharmony_ci</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>
14781cb0ef41Sopenharmony_ci<div class="api_metadata">
14791cb0ef41Sopenharmony_ci<span>Added in: v0.1.8</span>
14801cb0ef41Sopenharmony_ci</div>
14811cb0ef41Sopenharmony_ci<ul>
14821cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14831cb0ef41Sopenharmony_ci</ul>
14841cb0ef41Sopenharmony_ci<p>The <code>process.cwd()</code> method returns the current working directory of the Node.js
14851cb0ef41Sopenharmony_ciprocess.</p>
14861cb0ef41Sopenharmony_ci
14871cb0ef41Sopenharmony_ci<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>;
14881cb0ef41Sopenharmony_ci
14891cb0ef41Sopenharmony_ci<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>);
14901cb0ef41Sopenharmony_ci
14911cb0ef41Sopenharmony_ci<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>
14921cb0ef41Sopenharmony_ci</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>
14931cb0ef41Sopenharmony_ci<div class="api_metadata">
14941cb0ef41Sopenharmony_ci<span>Added in: v0.7.2</span>
14951cb0ef41Sopenharmony_ci</div>
14961cb0ef41Sopenharmony_ci<ul>
14971cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
14981cb0ef41Sopenharmony_ci</ul>
14991cb0ef41Sopenharmony_ci<p>The port used by the Node.js debugger when enabled.</p>
15001cb0ef41Sopenharmony_ci
15011cb0ef41Sopenharmony_ci<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>;
15021cb0ef41Sopenharmony_ci
15031cb0ef41Sopenharmony_ciprocess.<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>);
15041cb0ef41Sopenharmony_ci
15051cb0ef41Sopenharmony_ciprocess.<span class="hljs-property">debugPort</span> = <span class="hljs-number">5858</span>;</code><button class="copy-button">copy</button></pre>
15061cb0ef41Sopenharmony_ci</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>
15071cb0ef41Sopenharmony_ci<div class="api_metadata">
15081cb0ef41Sopenharmony_ci<span>Added in: v0.7.2</span>
15091cb0ef41Sopenharmony_ci</div>
15101cb0ef41Sopenharmony_ci<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
15111cb0ef41Sopenharmony_ciand <a href="cluster.html">Cluster</a> documentation), the <code>process.disconnect()</code> method will close the
15121cb0ef41Sopenharmony_ciIPC channel to the parent process, allowing the child process to exit gracefully
15131cb0ef41Sopenharmony_cionce there are no other connections keeping it alive.</p>
15141cb0ef41Sopenharmony_ci<p>The effect of calling <code>process.disconnect()</code> is the same as calling
15151cb0ef41Sopenharmony_ci<a href="child_process.html#subprocessdisconnect"><code>ChildProcess.disconnect()</code></a> from the parent process.</p>
15161cb0ef41Sopenharmony_ci<p>If the Node.js process was not spawned with an IPC channel,
15171cb0ef41Sopenharmony_ci<code>process.disconnect()</code> will be <code>undefined</code>.</p>
15181cb0ef41Sopenharmony_ci</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>
15191cb0ef41Sopenharmony_ci<div class="api_metadata">
15201cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
15211cb0ef41Sopenharmony_ci<table>
15221cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
15231cb0ef41Sopenharmony_ci<tr><td>v9.0.0</td>
15241cb0ef41Sopenharmony_ci<td><p>Added support for the <code>flags</code> argument.</p></td></tr>
15251cb0ef41Sopenharmony_ci<tr><td>v0.1.16</td>
15261cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.16</span></p></td></tr>
15271cb0ef41Sopenharmony_ci</tbody></table>
15281cb0ef41Sopenharmony_ci</details>
15291cb0ef41Sopenharmony_ci</div>
15301cb0ef41Sopenharmony_ci<ul>
15311cb0ef41Sopenharmony_ci<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>
15321cb0ef41Sopenharmony_ci<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>
15331cb0ef41Sopenharmony_ci<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>
15341cb0ef41Sopenharmony_ci</ul>
15351cb0ef41Sopenharmony_ci<p>The <code>process.dlopen()</code> method allows dynamically loading shared objects. It is
15361cb0ef41Sopenharmony_ciprimarily used by <code>require()</code> to load C++ Addons, and should not be used
15371cb0ef41Sopenharmony_cidirectly, except in special cases. In other words, <a href="globals.html#require"><code>require()</code></a> should be
15381cb0ef41Sopenharmony_cipreferred over <code>process.dlopen()</code> unless there are specific reasons such as
15391cb0ef41Sopenharmony_cicustom dlopen flags or loading from ES modules.</p>
15401cb0ef41Sopenharmony_ci<p>The <code>flags</code> argument is an integer that allows to specify dlopen
15411cb0ef41Sopenharmony_cibehavior. See the <a href="os.html#dlopen-constants"><code>os.constants.dlopen</code></a> documentation for details.</p>
15421cb0ef41Sopenharmony_ci<p>An important requirement when calling <code>process.dlopen()</code> is that the <code>module</code>
15431cb0ef41Sopenharmony_ciinstance must be passed. Functions exported by the C++ Addon are then
15441cb0ef41Sopenharmony_ciaccessible via <code>module.exports</code>.</p>
15451cb0ef41Sopenharmony_ci<p>The example below shows how to load a C++ Addon, named <code>local.node</code>,
15461cb0ef41Sopenharmony_cithat exports a <code>foo</code> function. All the symbols are loaded before
15471cb0ef41Sopenharmony_cithe call returns, by passing the <code>RTLD_NOW</code> constant. In this example
15481cb0ef41Sopenharmony_cithe constant is assumed to be available.</p>
15491cb0ef41Sopenharmony_ci
15501cb0ef41Sopenharmony_ci<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>;
15511cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { constants } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:os'</span>;
15521cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { fileURLToPath } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:url'</span>;
15531cb0ef41Sopenharmony_ci
15541cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} };
15551cb0ef41Sopenharmony_ci<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>)),
15561cb0ef41Sopenharmony_ci       constants.<span class="hljs-property">dlopen</span>.<span class="hljs-property">RTLD_NOW</span>);
15571cb0ef41Sopenharmony_ci<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>);
15581cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { constants } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:os'</span>);
15591cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { join } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:path'</span>);
15601cb0ef41Sopenharmony_ci
15611cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} };
15621cb0ef41Sopenharmony_ci<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>);
15631cb0ef41Sopenharmony_ci<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>
15641cb0ef41Sopenharmony_ci</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>
15651cb0ef41Sopenharmony_ci<div class="api_metadata">
15661cb0ef41Sopenharmony_ci<span>Added in: v8.0.0</span>
15671cb0ef41Sopenharmony_ci</div>
15681cb0ef41Sopenharmony_ci<ul>
15691cb0ef41Sopenharmony_ci<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>
15701cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
15711cb0ef41Sopenharmony_ci<ul>
15721cb0ef41Sopenharmony_ci<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
15731cb0ef41Sopenharmony_cifor the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
15741cb0ef41Sopenharmony_ci<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>
15751cb0ef41Sopenharmony_ci<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
15761cb0ef41Sopenharmony_cifunction used to limit the generated stack trace. <strong>Default:</strong>
15771cb0ef41Sopenharmony_ci<code>process.emitWarning</code>.</li>
15781cb0ef41Sopenharmony_ci<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>
15791cb0ef41Sopenharmony_ci</ul>
15801cb0ef41Sopenharmony_ci</li>
15811cb0ef41Sopenharmony_ci</ul>
15821cb0ef41Sopenharmony_ci<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
15831cb0ef41Sopenharmony_cispecific process warnings. These can be listened for by adding a handler to the
15841cb0ef41Sopenharmony_ci<a href="#event-warning"><code>'warning'</code></a> event.</p>
15851cb0ef41Sopenharmony_ci
15861cb0ef41Sopenharmony_ci<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>;
15871cb0ef41Sopenharmony_ci
15881cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning with a code and additional detail.</span>
15891cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, {
15901cb0ef41Sopenharmony_ci  <span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>,
15911cb0ef41Sopenharmony_ci  <span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>,
15921cb0ef41Sopenharmony_ci});
15931cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits:</span>
15941cb0ef41Sopenharmony_ci<span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span>
15951cb0ef41Sopenharmony_ci<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>);
15961cb0ef41Sopenharmony_ci
15971cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning with a code and additional detail.</span>
15981cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, {
15991cb0ef41Sopenharmony_ci  <span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>,
16001cb0ef41Sopenharmony_ci  <span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>,
16011cb0ef41Sopenharmony_ci});
16021cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits:</span>
16031cb0ef41Sopenharmony_ci<span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span>
16041cb0ef41Sopenharmony_ci<span class="hljs-comment">// This is some additional information</span></code><button class="copy-button">copy</button></pre>
16051cb0ef41Sopenharmony_ci<p>In this example, an <code>Error</code> object is generated internally by
16061cb0ef41Sopenharmony_ci<code>process.emitWarning()</code> and passed through to the
16071cb0ef41Sopenharmony_ci<a href="#event-warning"><code>'warning'</code></a> handler.</p>
16081cb0ef41Sopenharmony_ci
16091cb0ef41Sopenharmony_ci<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>;
16101cb0ef41Sopenharmony_ci
16111cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
16121cb0ef41Sopenharmony_ci  <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>
16131cb0ef41Sopenharmony_ci  <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>
16141cb0ef41Sopenharmony_ci  <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>
16151cb0ef41Sopenharmony_ci  <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>
16161cb0ef41Sopenharmony_ci  <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>
16171cb0ef41Sopenharmony_ci});</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>);
16181cb0ef41Sopenharmony_ci
16191cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
16201cb0ef41Sopenharmony_ci  <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>
16211cb0ef41Sopenharmony_ci  <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>
16221cb0ef41Sopenharmony_ci  <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>
16231cb0ef41Sopenharmony_ci  <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>
16241cb0ef41Sopenharmony_ci  <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>
16251cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
16261cb0ef41Sopenharmony_ci<p>If <code>warning</code> is passed as an <code>Error</code> object, the <code>options</code> argument is ignored.</p>
16271cb0ef41Sopenharmony_ci</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>
16281cb0ef41Sopenharmony_ci<div class="api_metadata">
16291cb0ef41Sopenharmony_ci<span>Added in: v6.0.0</span>
16301cb0ef41Sopenharmony_ci</div>
16311cb0ef41Sopenharmony_ci<ul>
16321cb0ef41Sopenharmony_ci<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>
16331cb0ef41Sopenharmony_ci<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
16341cb0ef41Sopenharmony_cifor the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
16351cb0ef41Sopenharmony_ci<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>
16361cb0ef41Sopenharmony_ci<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
16371cb0ef41Sopenharmony_cifunction used to limit the generated stack trace. <strong>Default:</strong>
16381cb0ef41Sopenharmony_ci<code>process.emitWarning</code>.</li>
16391cb0ef41Sopenharmony_ci</ul>
16401cb0ef41Sopenharmony_ci<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
16411cb0ef41Sopenharmony_cispecific process warnings. These can be listened for by adding a handler to the
16421cb0ef41Sopenharmony_ci<a href="#event-warning"><code>'warning'</code></a> event.</p>
16431cb0ef41Sopenharmony_ci
16441cb0ef41Sopenharmony_ci<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>;
16451cb0ef41Sopenharmony_ci
16461cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning using a string.</span>
16471cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>);
16481cb0ef41Sopenharmony_ci<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>);
16491cb0ef41Sopenharmony_ci
16501cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning using a string.</span>
16511cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>);
16521cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits: (node: 56338) Warning: Something happened!</span></code><button class="copy-button">copy</button></pre>
16531cb0ef41Sopenharmony_ci
16541cb0ef41Sopenharmony_ci<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>;
16551cb0ef41Sopenharmony_ci
16561cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning using a string and a type.</span>
16571cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>);
16581cb0ef41Sopenharmony_ci<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>);
16591cb0ef41Sopenharmony_ci
16601cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning using a string and a type.</span>
16611cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>);
16621cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits: (node:56338) CustomWarning: Something Happened!</span></code><button class="copy-button">copy</button></pre>
16631cb0ef41Sopenharmony_ci
16641cb0ef41Sopenharmony_ci<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>;
16651cb0ef41Sopenharmony_ci
16661cb0ef41Sopenharmony_ci<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>);
16671cb0ef41Sopenharmony_ci<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>);
16681cb0ef41Sopenharmony_ci
16691cb0ef41Sopenharmony_ciprocess.<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>);
16701cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre>
16711cb0ef41Sopenharmony_ci<p>In each of the previous examples, an <code>Error</code> object is generated internally by
16721cb0ef41Sopenharmony_ci<code>process.emitWarning()</code> and passed through to the <a href="#event-warning"><code>'warning'</code></a>
16731cb0ef41Sopenharmony_cihandler.</p>
16741cb0ef41Sopenharmony_ci
16751cb0ef41Sopenharmony_ci<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>;
16761cb0ef41Sopenharmony_ci
16771cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
16781cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);
16791cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>);
16801cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);
16811cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);
16821cb0ef41Sopenharmony_ci});</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>);
16831cb0ef41Sopenharmony_ci
16841cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
16851cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);
16861cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>);
16871cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);
16881cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);
16891cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
16901cb0ef41Sopenharmony_ci<p>If <code>warning</code> is passed as an <code>Error</code> object, it will be passed through to the
16911cb0ef41Sopenharmony_ci<code>'warning'</code> event handler unmodified (and the optional <code>type</code>,
16921cb0ef41Sopenharmony_ci<code>code</code> and <code>ctor</code> arguments will be ignored):</p>
16931cb0ef41Sopenharmony_ci
16941cb0ef41Sopenharmony_ci<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>;
16951cb0ef41Sopenharmony_ci
16961cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning using an Error object.</span>
16971cb0ef41Sopenharmony_ci<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>);
16981cb0ef41Sopenharmony_ci<span class="hljs-comment">// Use the Error name property to specify the type name</span>
16991cb0ef41Sopenharmony_cimyWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>;
17001cb0ef41Sopenharmony_cimyWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>;
17011cb0ef41Sopenharmony_ci
17021cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(myWarning);
17031cb0ef41Sopenharmony_ci<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>);
17041cb0ef41Sopenharmony_ci
17051cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emit a warning using an Error object.</span>
17061cb0ef41Sopenharmony_ci<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>);
17071cb0ef41Sopenharmony_ci<span class="hljs-comment">// Use the Error name property to specify the type name</span>
17081cb0ef41Sopenharmony_cimyWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>;
17091cb0ef41Sopenharmony_cimyWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>;
17101cb0ef41Sopenharmony_ci
17111cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitWarning</span>(myWarning);
17121cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre>
17131cb0ef41Sopenharmony_ci<p>A <code>TypeError</code> is thrown if <code>warning</code> is anything other than a string or <code>Error</code>
17141cb0ef41Sopenharmony_ciobject.</p>
17151cb0ef41Sopenharmony_ci<p>While process warnings use <code>Error</code> objects, the process warning
17161cb0ef41Sopenharmony_cimechanism is <strong>not</strong> a replacement for normal error handling mechanisms.</p>
17171cb0ef41Sopenharmony_ci<p>The following additional handling is implemented if the warning <code>type</code> is
17181cb0ef41Sopenharmony_ci<code>'DeprecationWarning'</code>:</p>
17191cb0ef41Sopenharmony_ci<ul>
17201cb0ef41Sopenharmony_ci<li>If the <code>--throw-deprecation</code> command-line flag is used, the deprecation
17211cb0ef41Sopenharmony_ciwarning is thrown as an exception rather than being emitted as an event.</li>
17221cb0ef41Sopenharmony_ci<li>If the <code>--no-deprecation</code> command-line flag is used, the deprecation
17231cb0ef41Sopenharmony_ciwarning is suppressed.</li>
17241cb0ef41Sopenharmony_ci<li>If the <code>--trace-deprecation</code> command-line flag is used, the deprecation
17251cb0ef41Sopenharmony_ciwarning is printed to <code>stderr</code> along with the full stack trace.</li>
17261cb0ef41Sopenharmony_ci</ul>
17271cb0ef41Sopenharmony_ci<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>
17281cb0ef41Sopenharmony_ci<p>As a best practice, warnings should be emitted only once per process. To do
17291cb0ef41Sopenharmony_ciso, place the <code>emitWarning()</code> behind a boolean.</p>
17301cb0ef41Sopenharmony_ci
17311cb0ef41Sopenharmony_ci<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>;
17321cb0ef41Sopenharmony_ci
17331cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) {
17341cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) {
17351cb0ef41Sopenharmony_ci    emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>;
17361cb0ef41Sopenharmony_ci    <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>);
17371cb0ef41Sopenharmony_ci  }
17381cb0ef41Sopenharmony_ci}
17391cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitMyWarning</span>();
17401cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span>
17411cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitMyWarning</span>();
17421cb0ef41Sopenharmony_ci<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>);
17431cb0ef41Sopenharmony_ci
17441cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) {
17451cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) {
17461cb0ef41Sopenharmony_ci    emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>;
17471cb0ef41Sopenharmony_ci    <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>);
17481cb0ef41Sopenharmony_ci  }
17491cb0ef41Sopenharmony_ci}
17501cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitMyWarning</span>();
17511cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span>
17521cb0ef41Sopenharmony_ci<span class="hljs-title function_">emitMyWarning</span>();
17531cb0ef41Sopenharmony_ci<span class="hljs-comment">// Emits nothing</span></code><button class="copy-button">copy</button></pre>
17541cb0ef41Sopenharmony_ci</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>
17551cb0ef41Sopenharmony_ci<div class="api_metadata">
17561cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
17571cb0ef41Sopenharmony_ci<table>
17581cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
17591cb0ef41Sopenharmony_ci<tr><td>v11.14.0</td>
17601cb0ef41Sopenharmony_ci<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>
17611cb0ef41Sopenharmony_ci<tr><td>v10.0.0</td>
17621cb0ef41Sopenharmony_ci<td><p>Implicit conversion of variable value to string is deprecated.</p></td></tr>
17631cb0ef41Sopenharmony_ci<tr><td>v0.1.27</td>
17641cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.27</span></p></td></tr>
17651cb0ef41Sopenharmony_ci</tbody></table>
17661cb0ef41Sopenharmony_ci</details>
17671cb0ef41Sopenharmony_ci</div>
17681cb0ef41Sopenharmony_ci<ul>
17691cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
17701cb0ef41Sopenharmony_ci</ul>
17711cb0ef41Sopenharmony_ci<p>The <code>process.env</code> property returns an object containing the user environment.
17721cb0ef41Sopenharmony_ciSee <a href="http://man7.org/linux/man-pages/man7/environ.7.html"><code>environ(7)</code></a>.</p>
17731cb0ef41Sopenharmony_ci<p>An example of this object looks like:</p>
17741cb0ef41Sopenharmony_ci<!-- eslint-skip -->
17751cb0ef41Sopenharmony_ci<pre><code class="language-js">{
17761cb0ef41Sopenharmony_ci  <span class="hljs-attr">TERM</span>: <span class="hljs-string">'xterm-256color'</span>,
17771cb0ef41Sopenharmony_ci  <span class="hljs-attr">SHELL</span>: <span class="hljs-string">'/usr/local/bin/bash'</span>,
17781cb0ef41Sopenharmony_ci  <span class="hljs-attr">USER</span>: <span class="hljs-string">'maciej'</span>,
17791cb0ef41Sopenharmony_ci  <span class="hljs-attr">PATH</span>: <span class="hljs-string">'~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'</span>,
17801cb0ef41Sopenharmony_ci  <span class="hljs-attr">PWD</span>: <span class="hljs-string">'/Users/maciej'</span>,
17811cb0ef41Sopenharmony_ci  <span class="hljs-attr">EDITOR</span>: <span class="hljs-string">'vim'</span>,
17821cb0ef41Sopenharmony_ci  <span class="hljs-attr">SHLVL</span>: <span class="hljs-string">'1'</span>,
17831cb0ef41Sopenharmony_ci  <span class="hljs-attr">HOME</span>: <span class="hljs-string">'/Users/maciej'</span>,
17841cb0ef41Sopenharmony_ci  <span class="hljs-attr">LOGNAME</span>: <span class="hljs-string">'maciej'</span>,
17851cb0ef41Sopenharmony_ci  <span class="hljs-attr">_</span>: <span class="hljs-string">'/usr/local/bin/node'</span>
17861cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
17871cb0ef41Sopenharmony_ci<p>It is possible to modify this object, but such modifications will not be
17881cb0ef41Sopenharmony_cireflected outside the Node.js process, or (unless explicitly requested)
17891cb0ef41Sopenharmony_cito other <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.
17901cb0ef41Sopenharmony_ciIn other words, the following example would not work:</p>
17911cb0ef41Sopenharmony_ci<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>
17921cb0ef41Sopenharmony_ci<p>While the following will:</p>
17931cb0ef41Sopenharmony_ci
17941cb0ef41Sopenharmony_ci<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>;
17951cb0ef41Sopenharmony_ci
17961cb0ef41Sopenharmony_cienv.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>;
17971cb0ef41Sopenharmony_ci<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>);
17981cb0ef41Sopenharmony_ci
17991cb0ef41Sopenharmony_cienv.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>;
18001cb0ef41Sopenharmony_ci<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>
18011cb0ef41Sopenharmony_ci<p>Assigning a property on <code>process.env</code> will implicitly convert the value
18021cb0ef41Sopenharmony_cito a string. <strong>This behavior is deprecated.</strong> Future versions of Node.js may
18031cb0ef41Sopenharmony_cithrow an error when the value is not a string, number, or boolean.</p>
18041cb0ef41Sopenharmony_ci
18051cb0ef41Sopenharmony_ci<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>;
18061cb0ef41Sopenharmony_ci
18071cb0ef41Sopenharmony_cienv.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>;
18081cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
18091cb0ef41Sopenharmony_ci<span class="hljs-comment">// => 'null'</span>
18101cb0ef41Sopenharmony_cienv.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>;
18111cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
18121cb0ef41Sopenharmony_ci<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>);
18131cb0ef41Sopenharmony_ci
18141cb0ef41Sopenharmony_cienv.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>;
18151cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
18161cb0ef41Sopenharmony_ci<span class="hljs-comment">// => 'null'</span>
18171cb0ef41Sopenharmony_cienv.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>;
18181cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
18191cb0ef41Sopenharmony_ci<span class="hljs-comment">// => 'undefined'</span></code><button class="copy-button">copy</button></pre>
18201cb0ef41Sopenharmony_ci<p>Use <code>delete</code> to delete a property from <code>process.env</code>.</p>
18211cb0ef41Sopenharmony_ci
18221cb0ef41Sopenharmony_ci<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>;
18231cb0ef41Sopenharmony_ci
18241cb0ef41Sopenharmony_cienv.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
18251cb0ef41Sopenharmony_ci<span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>;
18261cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>);
18271cb0ef41Sopenharmony_ci<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>);
18281cb0ef41Sopenharmony_ci
18291cb0ef41Sopenharmony_cienv.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
18301cb0ef41Sopenharmony_ci<span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>;
18311cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>);
18321cb0ef41Sopenharmony_ci<span class="hljs-comment">// => undefined</span></code><button class="copy-button">copy</button></pre>
18331cb0ef41Sopenharmony_ci<p>On Windows operating systems, environment variables are case-insensitive.</p>
18341cb0ef41Sopenharmony_ci
18351cb0ef41Sopenharmony_ci<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>;
18361cb0ef41Sopenharmony_ci
18371cb0ef41Sopenharmony_cienv.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
18381cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
18391cb0ef41Sopenharmony_ci<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>);
18401cb0ef41Sopenharmony_ci
18411cb0ef41Sopenharmony_cienv.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
18421cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
18431cb0ef41Sopenharmony_ci<span class="hljs-comment">// => 1</span></code><button class="copy-button">copy</button></pre>
18441cb0ef41Sopenharmony_ci<p>Unless explicitly specified when creating a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance,
18451cb0ef41Sopenharmony_cieach <a href="worker_threads.html#class-worker"><code>Worker</code></a> thread has its own copy of <code>process.env</code>, based on its
18461cb0ef41Sopenharmony_ciparent thread's <code>process.env</code>, or whatever was specified as the <code>env</code> option
18471cb0ef41Sopenharmony_cito the <a href="worker_threads.html#class-worker"><code>Worker</code></a> constructor. Changes to <code>process.env</code> will not be visible
18481cb0ef41Sopenharmony_ciacross <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, and only the main thread can make changes that
18491cb0ef41Sopenharmony_ciare visible to the operating system or to native add-ons. On Windows, a copy of
18501cb0ef41Sopenharmony_ci<code>process.env</code> on a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance operates in a case-sensitive manner
18511cb0ef41Sopenharmony_ciunlike the main thread.</p>
18521cb0ef41Sopenharmony_ci</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>
18531cb0ef41Sopenharmony_ci<div class="api_metadata">
18541cb0ef41Sopenharmony_ci<span>Added in: v0.7.7</span>
18551cb0ef41Sopenharmony_ci</div>
18561cb0ef41Sopenharmony_ci<ul>
18571cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
18581cb0ef41Sopenharmony_ci</ul>
18591cb0ef41Sopenharmony_ci<p>The <code>process.execArgv</code> property returns the set of Node.js-specific command-line
18601cb0ef41Sopenharmony_cioptions passed when the Node.js process was launched. These options do not
18611cb0ef41Sopenharmony_ciappear in the array returned by the <a href="#processargv"><code>process.argv</code></a> property, and do not
18621cb0ef41Sopenharmony_ciinclude the Node.js executable, the name of the script, or any options following
18631cb0ef41Sopenharmony_cithe script name. These options are useful in order to spawn child processes with
18641cb0ef41Sopenharmony_cithe same execution environment as the parent.</p>
18651cb0ef41Sopenharmony_ci<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>
18661cb0ef41Sopenharmony_ci<p>Results in <code>process.execArgv</code>:</p>
18671cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
18681cb0ef41Sopenharmony_ci<pre><code class="language-js">[<span class="hljs-string">'--harmony'</span>]</code> <button class="copy-button">copy</button></pre>
18691cb0ef41Sopenharmony_ci<p>And <code>process.argv</code>:</p>
18701cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
18711cb0ef41Sopenharmony_ci<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>
18721cb0ef41Sopenharmony_ci<p>Refer to <a href="worker_threads.html#new-workerfilename-options"><code>Worker</code> constructor</a> for the detailed behavior of worker
18731cb0ef41Sopenharmony_cithreads with this property.</p>
18741cb0ef41Sopenharmony_ci</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>
18751cb0ef41Sopenharmony_ci<div class="api_metadata">
18761cb0ef41Sopenharmony_ci<span>Added in: v0.1.100</span>
18771cb0ef41Sopenharmony_ci</div>
18781cb0ef41Sopenharmony_ci<ul>
18791cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
18801cb0ef41Sopenharmony_ci</ul>
18811cb0ef41Sopenharmony_ci<p>The <code>process.execPath</code> property returns the absolute pathname of the executable
18821cb0ef41Sopenharmony_cithat started the Node.js process. Symbolic links, if any, are resolved.</p>
18831cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
18841cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-string">'/usr/local/bin/node'</span></code> <button class="copy-button">copy</button></pre>
18851cb0ef41Sopenharmony_ci</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>
18861cb0ef41Sopenharmony_ci<div class="api_metadata">
18871cb0ef41Sopenharmony_ci<span>Added in: v0.1.13</span>
18881cb0ef41Sopenharmony_ci</div>
18891cb0ef41Sopenharmony_ci<ul>
18901cb0ef41Sopenharmony_ci<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>
18911cb0ef41Sopenharmony_ci</ul>
18921cb0ef41Sopenharmony_ci<p>The <code>process.exit()</code> method instructs Node.js to terminate the process
18931cb0ef41Sopenharmony_cisynchronously with an exit status of <code>code</code>. If <code>code</code> is omitted, exit uses
18941cb0ef41Sopenharmony_cieither the 'success' code <code>0</code> or the value of <code>process.exitCode</code> if it has been
18951cb0ef41Sopenharmony_ciset. Node.js will not terminate until all the <a href="#event-exit"><code>'exit'</code></a> event listeners are
18961cb0ef41Sopenharmony_cicalled.</p>
18971cb0ef41Sopenharmony_ci<p>To exit with a 'failure' code:</p>
18981cb0ef41Sopenharmony_ci
18991cb0ef41Sopenharmony_ci<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>;
19001cb0ef41Sopenharmony_ci
19011cb0ef41Sopenharmony_ci<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>);
19021cb0ef41Sopenharmony_ci
19031cb0ef41Sopenharmony_ci<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);</code><button class="copy-button">copy</button></pre>
19041cb0ef41Sopenharmony_ci<p>The shell that executed Node.js should see the exit code as <code>1</code>.</p>
19051cb0ef41Sopenharmony_ci<p>Calling <code>process.exit()</code> will force the process to exit as quickly as possible
19061cb0ef41Sopenharmony_cieven if there are still asynchronous operations pending that have not yet
19071cb0ef41Sopenharmony_cicompleted fully, including I/O operations to <code>process.stdout</code> and
19081cb0ef41Sopenharmony_ci<code>process.stderr</code>.</p>
19091cb0ef41Sopenharmony_ci<p>In most situations, it is not actually necessary to call <code>process.exit()</code>
19101cb0ef41Sopenharmony_ciexplicitly. The Node.js process will exit on its own <em>if there is no additional
19111cb0ef41Sopenharmony_ciwork pending</em> in the event loop. The <code>process.exitCode</code> property can be set to
19121cb0ef41Sopenharmony_citell the process which exit code to use when the process exits gracefully.</p>
19131cb0ef41Sopenharmony_ci<p>For instance, the following example illustrates a <em>misuse</em> of the
19141cb0ef41Sopenharmony_ci<code>process.exit()</code> method that could lead to data printed to stdout being
19151cb0ef41Sopenharmony_citruncated and lost:</p>
19161cb0ef41Sopenharmony_ci
19171cb0ef41Sopenharmony_ci<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>;
19181cb0ef41Sopenharmony_ci
19191cb0ef41Sopenharmony_ci<span class="hljs-comment">// This is an example of what *not* to do:</span>
19201cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
19211cb0ef41Sopenharmony_ci  <span class="hljs-title function_">printUsageToStdout</span>();
19221cb0ef41Sopenharmony_ci  <span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);
19231cb0ef41Sopenharmony_ci}</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>);
19241cb0ef41Sopenharmony_ci
19251cb0ef41Sopenharmony_ci<span class="hljs-comment">// This is an example of what *not* to do:</span>
19261cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
19271cb0ef41Sopenharmony_ci  <span class="hljs-title function_">printUsageToStdout</span>();
19281cb0ef41Sopenharmony_ci  <span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);
19291cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
19301cb0ef41Sopenharmony_ci<p>The reason this is problematic is because writes to <code>process.stdout</code> in Node.js
19311cb0ef41Sopenharmony_ciare sometimes <em>asynchronous</em> and may occur over multiple ticks of the Node.js
19321cb0ef41Sopenharmony_cievent loop. Calling <code>process.exit()</code>, however, forces the process to exit
19331cb0ef41Sopenharmony_ci<em>before</em> those additional writes to <code>stdout</code> can be performed.</p>
19341cb0ef41Sopenharmony_ci<p>Rather than calling <code>process.exit()</code> directly, the code <em>should</em> set the
19351cb0ef41Sopenharmony_ci<code>process.exitCode</code> and allow the process to exit naturally by avoiding
19361cb0ef41Sopenharmony_cischeduling any additional work for the event loop:</p>
19371cb0ef41Sopenharmony_ci
19381cb0ef41Sopenharmony_ci<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>;
19391cb0ef41Sopenharmony_ci
19401cb0ef41Sopenharmony_ci<span class="hljs-comment">// How to properly set the exit code while letting</span>
19411cb0ef41Sopenharmony_ci<span class="hljs-comment">// the process exit gracefully.</span>
19421cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
19431cb0ef41Sopenharmony_ci  <span class="hljs-title function_">printUsageToStdout</span>();
19441cb0ef41Sopenharmony_ci  process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
19451cb0ef41Sopenharmony_ci}</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>);
19461cb0ef41Sopenharmony_ci
19471cb0ef41Sopenharmony_ci<span class="hljs-comment">// How to properly set the exit code while letting</span>
19481cb0ef41Sopenharmony_ci<span class="hljs-comment">// the process exit gracefully.</span>
19491cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
19501cb0ef41Sopenharmony_ci  <span class="hljs-title function_">printUsageToStdout</span>();
19511cb0ef41Sopenharmony_ci  process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
19521cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
19531cb0ef41Sopenharmony_ci<p>If it is necessary to terminate the Node.js process due to an error condition,
19541cb0ef41Sopenharmony_cithrowing an <em>uncaught</em> error and allowing the process to terminate accordingly
19551cb0ef41Sopenharmony_ciis safer than calling <code>process.exit()</code>.</p>
19561cb0ef41Sopenharmony_ci<p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, this function stops the current thread rather
19571cb0ef41Sopenharmony_cithan the current process.</p>
19581cb0ef41Sopenharmony_ci</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>
19591cb0ef41Sopenharmony_ci<div class="api_metadata">
19601cb0ef41Sopenharmony_ci<span>Added in: v0.11.8</span>
19611cb0ef41Sopenharmony_ci</div>
19621cb0ef41Sopenharmony_ci<ul>
19631cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
19641cb0ef41Sopenharmony_ci</ul>
19651cb0ef41Sopenharmony_ci<p>A number which will be the process exit code, when the process either
19661cb0ef41Sopenharmony_ciexits gracefully, or is exited via <a href="#processexitcode"><code>process.exit()</code></a> without specifying
19671cb0ef41Sopenharmony_cia code.</p>
19681cb0ef41Sopenharmony_ci<p>Specifying a code to <a href="#processexitcode"><code>process.exit(code)</code></a> will override any
19691cb0ef41Sopenharmony_ciprevious setting of <code>process.exitCode</code>.</p>
19701cb0ef41Sopenharmony_ci</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>
19711cb0ef41Sopenharmony_ci<div class="api_metadata">
19721cb0ef41Sopenharmony_ci<span>Added in: v17.3.0, v16.14.0</span>
19731cb0ef41Sopenharmony_ci</div>
19741cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
19751cb0ef41Sopenharmony_ci<ul>
19761cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
19771cb0ef41Sopenharmony_ci</ul>
19781cb0ef41Sopenharmony_ci<p>The <code>process.getActiveResourcesInfo()</code> method returns an array of strings
19791cb0ef41Sopenharmony_cicontaining the types of the active resources that are currently keeping the
19801cb0ef41Sopenharmony_cievent loop alive.</p>
19811cb0ef41Sopenharmony_ci
19821cb0ef41Sopenharmony_ci<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>;
19831cb0ef41Sopenharmony_ci<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>;
19841cb0ef41Sopenharmony_ci
19851cb0ef41Sopenharmony_ci<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>());
19861cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>);
19871cb0ef41Sopenharmony_ci<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>());
19881cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
19891cb0ef41Sopenharmony_ci<span class="hljs-comment">//   Before: [ 'CloseReq', 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span>
19901cb0ef41Sopenharmony_ci<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>);
19911cb0ef41Sopenharmony_ci<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>);
19921cb0ef41Sopenharmony_ci
19931cb0ef41Sopenharmony_ci<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>());
19941cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>);
19951cb0ef41Sopenharmony_ci<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>());
19961cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
19971cb0ef41Sopenharmony_ci<span class="hljs-comment">//   Before: [ 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span>
19981cb0ef41Sopenharmony_ci<span class="hljs-comment">//   After: [ 'TTYWrap', 'TTYWrap', 'TTYWrap', 'Timeout' ]</span></code><button class="copy-button">copy</button></pre>
19991cb0ef41Sopenharmony_ci</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>
20001cb0ef41Sopenharmony_ci<div class="api_metadata">
20011cb0ef41Sopenharmony_ci<span>Added in: v2.0.0</span>
20021cb0ef41Sopenharmony_ci</div>
20031cb0ef41Sopenharmony_ci<p>The <code>process.getegid()</code> method returns the numerical effective group identity
20041cb0ef41Sopenharmony_ciof the Node.js process. (See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html"><code>getegid(2)</code></a>.)</p>
20051cb0ef41Sopenharmony_ci
20061cb0ef41Sopenharmony_ci<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>;
20071cb0ef41Sopenharmony_ci
20081cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) {
20091cb0ef41Sopenharmony_ci  <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>);
20101cb0ef41Sopenharmony_ci}</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>);
20111cb0ef41Sopenharmony_ci
20121cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) {
20131cb0ef41Sopenharmony_ci  <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>);
20141cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
20151cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
20161cb0ef41Sopenharmony_ciAndroid).</p>
20171cb0ef41Sopenharmony_ci</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>
20181cb0ef41Sopenharmony_ci<div class="api_metadata">
20191cb0ef41Sopenharmony_ci<span>Added in: v2.0.0</span>
20201cb0ef41Sopenharmony_ci</div>
20211cb0ef41Sopenharmony_ci<ul>
20221cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
20231cb0ef41Sopenharmony_ci</ul>
20241cb0ef41Sopenharmony_ci<p>The <code>process.geteuid()</code> method returns the numerical effective user identity of
20251cb0ef41Sopenharmony_cithe process. (See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html"><code>geteuid(2)</code></a>.)</p>
20261cb0ef41Sopenharmony_ci
20271cb0ef41Sopenharmony_ci<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>;
20281cb0ef41Sopenharmony_ci
20291cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) {
20301cb0ef41Sopenharmony_ci  <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>);
20311cb0ef41Sopenharmony_ci}</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>);
20321cb0ef41Sopenharmony_ci
20331cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) {
20341cb0ef41Sopenharmony_ci  <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>);
20351cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
20361cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
20371cb0ef41Sopenharmony_ciAndroid).</p>
20381cb0ef41Sopenharmony_ci</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>
20391cb0ef41Sopenharmony_ci<div class="api_metadata">
20401cb0ef41Sopenharmony_ci<span>Added in: v0.1.31</span>
20411cb0ef41Sopenharmony_ci</div>
20421cb0ef41Sopenharmony_ci<ul>
20431cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
20441cb0ef41Sopenharmony_ci</ul>
20451cb0ef41Sopenharmony_ci<p>The <code>process.getgid()</code> method returns the numerical group identity of the
20461cb0ef41Sopenharmony_ciprocess. (See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html"><code>getgid(2)</code></a>.)</p>
20471cb0ef41Sopenharmony_ci
20481cb0ef41Sopenharmony_ci<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>;
20491cb0ef41Sopenharmony_ci
20501cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) {
20511cb0ef41Sopenharmony_ci  <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>);
20521cb0ef41Sopenharmony_ci}</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>);
20531cb0ef41Sopenharmony_ci
20541cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) {
20551cb0ef41Sopenharmony_ci  <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>);
20561cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
20571cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
20581cb0ef41Sopenharmony_ciAndroid).</p>
20591cb0ef41Sopenharmony_ci</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>
20601cb0ef41Sopenharmony_ci<div class="api_metadata">
20611cb0ef41Sopenharmony_ci<span>Added in: v0.9.4</span>
20621cb0ef41Sopenharmony_ci</div>
20631cb0ef41Sopenharmony_ci<ul>
20641cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
20651cb0ef41Sopenharmony_ci</ul>
20661cb0ef41Sopenharmony_ci<p>The <code>process.getgroups()</code> method returns an array with the supplementary group
20671cb0ef41Sopenharmony_ciIDs. POSIX leaves it unspecified if the effective group ID is included but
20681cb0ef41Sopenharmony_ciNode.js ensures it always is.</p>
20691cb0ef41Sopenharmony_ci
20701cb0ef41Sopenharmony_ci<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>;
20711cb0ef41Sopenharmony_ci
20721cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) {
20731cb0ef41Sopenharmony_ci  <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>
20741cb0ef41Sopenharmony_ci}</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>);
20751cb0ef41Sopenharmony_ci
20761cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) {
20771cb0ef41Sopenharmony_ci  <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>
20781cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
20791cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
20801cb0ef41Sopenharmony_ciAndroid).</p>
20811cb0ef41Sopenharmony_ci</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>
20821cb0ef41Sopenharmony_ci<div class="api_metadata">
20831cb0ef41Sopenharmony_ci<span>Added in: v0.1.28</span>
20841cb0ef41Sopenharmony_ci</div>
20851cb0ef41Sopenharmony_ci<ul>
20861cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
20871cb0ef41Sopenharmony_ci</ul>
20881cb0ef41Sopenharmony_ci<p>The <code>process.getuid()</code> method returns the numeric user identity of the process.
20891cb0ef41Sopenharmony_ci(See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html"><code>getuid(2)</code></a>.)</p>
20901cb0ef41Sopenharmony_ci
20911cb0ef41Sopenharmony_ci<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>;
20921cb0ef41Sopenharmony_ci
20931cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) {
20941cb0ef41Sopenharmony_ci  <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>);
20951cb0ef41Sopenharmony_ci}</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>);
20961cb0ef41Sopenharmony_ci
20971cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) {
20981cb0ef41Sopenharmony_ci  <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>);
20991cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
21001cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
21011cb0ef41Sopenharmony_ciAndroid).</p>
21021cb0ef41Sopenharmony_ci</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>
21031cb0ef41Sopenharmony_ci<div class="api_metadata">
21041cb0ef41Sopenharmony_ci<span>Added in: v9.3.0</span>
21051cb0ef41Sopenharmony_ci</div>
21061cb0ef41Sopenharmony_ci<ul>
21071cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
21081cb0ef41Sopenharmony_ci</ul>
21091cb0ef41Sopenharmony_ci<p>Indicates whether a callback has been set using
21101cb0ef41Sopenharmony_ci<a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a>.</p>
21111cb0ef41Sopenharmony_ci</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>
21121cb0ef41Sopenharmony_ci<div class="api_metadata">
21131cb0ef41Sopenharmony_ci<span>Added in: v0.7.6</span>
21141cb0ef41Sopenharmony_ci</div>
21151cb0ef41Sopenharmony_ci<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>
21161cb0ef41Sopenharmony_ci<ul>
21171cb0ef41Sopenharmony_ci<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>
21181cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer[]></a></li>
21191cb0ef41Sopenharmony_ci</ul>
21201cb0ef41Sopenharmony_ci<p>This is the legacy version of <a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a>
21211cb0ef41Sopenharmony_cibefore <code>bigint</code> was introduced in JavaScript.</p>
21221cb0ef41Sopenharmony_ci<p>The <code>process.hrtime()</code> method returns the current high-resolution real time
21231cb0ef41Sopenharmony_ciin a <code>[seconds, nanoseconds]</code> tuple <code>Array</code>, where <code>nanoseconds</code> is the
21241cb0ef41Sopenharmony_ciremaining part of the real time that can't be represented in second precision.</p>
21251cb0ef41Sopenharmony_ci<p><code>time</code> is an optional parameter that must be the result of a previous
21261cb0ef41Sopenharmony_ci<code>process.hrtime()</code> call to diff with the current time. If the parameter
21271cb0ef41Sopenharmony_cipassed in is not a tuple <code>Array</code>, a <code>TypeError</code> will be thrown. Passing in a
21281cb0ef41Sopenharmony_ciuser-defined array instead of the result of a previous call to
21291cb0ef41Sopenharmony_ci<code>process.hrtime()</code> will lead to undefined behavior.</p>
21301cb0ef41Sopenharmony_ci<p>These times are relative to an arbitrary time in the
21311cb0ef41Sopenharmony_cipast, and not related to the time of day and therefore not subject to clock
21321cb0ef41Sopenharmony_cidrift. The primary use is for measuring performance between intervals:</p>
21331cb0ef41Sopenharmony_ci
21341cb0ef41Sopenharmony_ci<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>;
21351cb0ef41Sopenharmony_ci
21361cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>;
21371cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>();
21381cb0ef41Sopenharmony_ci<span class="hljs-comment">// [ 1800216, 25 ]</span>
21391cb0ef41Sopenharmony_ci
21401cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
21411cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time);
21421cb0ef41Sopenharmony_ci  <span class="hljs-comment">// [ 1, 552 ]</span>
21431cb0ef41Sopenharmony_ci
21441cb0ef41Sopenharmony_ci  <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>);
21451cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span>
21461cb0ef41Sopenharmony_ci}, <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>);
21471cb0ef41Sopenharmony_ci
21481cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>;
21491cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>();
21501cb0ef41Sopenharmony_ci<span class="hljs-comment">// [ 1800216, 25 ]</span>
21511cb0ef41Sopenharmony_ci
21521cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
21531cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time);
21541cb0ef41Sopenharmony_ci  <span class="hljs-comment">// [ 1, 552 ]</span>
21551cb0ef41Sopenharmony_ci
21561cb0ef41Sopenharmony_ci  <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>);
21571cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span>
21581cb0ef41Sopenharmony_ci}, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre>
21591cb0ef41Sopenharmony_ci</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>
21601cb0ef41Sopenharmony_ci<div class="api_metadata">
21611cb0ef41Sopenharmony_ci<span>Added in: v10.7.0</span>
21621cb0ef41Sopenharmony_ci</div>
21631cb0ef41Sopenharmony_ci<ul>
21641cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
21651cb0ef41Sopenharmony_ci</ul>
21661cb0ef41Sopenharmony_ci<p>The <code>bigint</code> version of the <a href="#processhrtimetime"><code>process.hrtime()</code></a> method returning the
21671cb0ef41Sopenharmony_cicurrent high-resolution real time in nanoseconds as a <code>bigint</code>.</p>
21681cb0ef41Sopenharmony_ci<p>Unlike <a href="#processhrtimetime"><code>process.hrtime()</code></a>, it does not support an additional <code>time</code>
21691cb0ef41Sopenharmony_ciargument since the difference can just be computed directly
21701cb0ef41Sopenharmony_ciby subtraction of the two <code>bigint</code>s.</p>
21711cb0ef41Sopenharmony_ci
21721cb0ef41Sopenharmony_ci<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>;
21731cb0ef41Sopenharmony_ci
21741cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>();
21751cb0ef41Sopenharmony_ci<span class="hljs-comment">// 191051479007711n</span>
21761cb0ef41Sopenharmony_ci
21771cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
21781cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>();
21791cb0ef41Sopenharmony_ci  <span class="hljs-comment">// 191052633396993n</span>
21801cb0ef41Sopenharmony_ci
21811cb0ef41Sopenharmony_ci  <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>);
21821cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span>
21831cb0ef41Sopenharmony_ci}, <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>);
21841cb0ef41Sopenharmony_ci
21851cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>();
21861cb0ef41Sopenharmony_ci<span class="hljs-comment">// 191051479007711n</span>
21871cb0ef41Sopenharmony_ci
21881cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
21891cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>();
21901cb0ef41Sopenharmony_ci  <span class="hljs-comment">// 191052633396993n</span>
21911cb0ef41Sopenharmony_ci
21921cb0ef41Sopenharmony_ci  <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>);
21931cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span>
21941cb0ef41Sopenharmony_ci}, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre>
21951cb0ef41Sopenharmony_ci</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>
21961cb0ef41Sopenharmony_ci<div class="api_metadata">
21971cb0ef41Sopenharmony_ci<span>Added in: v0.9.4</span>
21981cb0ef41Sopenharmony_ci</div>
21991cb0ef41Sopenharmony_ci<ul>
22001cb0ef41Sopenharmony_ci<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>
22011cb0ef41Sopenharmony_ci<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>
22021cb0ef41Sopenharmony_ci</ul>
22031cb0ef41Sopenharmony_ci<p>The <code>process.initgroups()</code> method reads the <code>/etc/group</code> file and initializes
22041cb0ef41Sopenharmony_cithe group access list, using all groups of which the user is a member. This is
22051cb0ef41Sopenharmony_cia privileged operation that requires that the Node.js process either have <code>root</code>
22061cb0ef41Sopenharmony_ciaccess or the <code>CAP_SETGID</code> capability.</p>
22071cb0ef41Sopenharmony_ci<p>Use care when dropping privileges:</p>
22081cb0ef41Sopenharmony_ci
22091cb0ef41Sopenharmony_ci<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>;
22101cb0ef41Sopenharmony_ci
22111cb0ef41Sopenharmony_ci<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>
22121cb0ef41Sopenharmony_ci<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>
22131cb0ef41Sopenharmony_ci<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>
22141cb0ef41Sopenharmony_ci<span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>);                     <span class="hljs-comment">// drop root gid</span>
22151cb0ef41Sopenharmony_ci<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>);
22161cb0ef41Sopenharmony_ci
22171cb0ef41Sopenharmony_ci<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>
22181cb0ef41Sopenharmony_ci<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>
22191cb0ef41Sopenharmony_ci<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>
22201cb0ef41Sopenharmony_ci<span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>);                     <span class="hljs-comment">// drop root gid</span>
22211cb0ef41Sopenharmony_ci<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>
22221cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
22231cb0ef41Sopenharmony_ciAndroid).
22241cb0ef41Sopenharmony_ciThis feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
22251cb0ef41Sopenharmony_ci</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>
22261cb0ef41Sopenharmony_ci<div class="api_metadata">
22271cb0ef41Sopenharmony_ci<span>Added in: v0.0.6</span>
22281cb0ef41Sopenharmony_ci</div>
22291cb0ef41Sopenharmony_ci<ul>
22301cb0ef41Sopenharmony_ci<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>
22311cb0ef41Sopenharmony_ci<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.
22321cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>'SIGTERM'</code>.</li>
22331cb0ef41Sopenharmony_ci</ul>
22341cb0ef41Sopenharmony_ci<p>The <code>process.kill()</code> method sends the <code>signal</code> to the process identified by
22351cb0ef41Sopenharmony_ci<code>pid</code>.</p>
22361cb0ef41Sopenharmony_ci<p>Signal names are strings such as <code>'SIGINT'</code> or <code>'SIGHUP'</code>. See <a href="#signal-events">Signal Events</a>
22371cb0ef41Sopenharmony_ciand <a href="http://man7.org/linux/man-pages/man2/kill.2.html"><code>kill(2)</code></a> for more information.</p>
22381cb0ef41Sopenharmony_ci<p>This method will throw an error if the target <code>pid</code> does not exist. As a special
22391cb0ef41Sopenharmony_cicase, a signal of <code>0</code> can be used to test for the existence of a process.
22401cb0ef41Sopenharmony_ciWindows platforms will throw an error if the <code>pid</code> is used to kill a process
22411cb0ef41Sopenharmony_cigroup.</p>
22421cb0ef41Sopenharmony_ci<p>Even though the name of this function is <code>process.kill()</code>, it is really just a
22431cb0ef41Sopenharmony_cisignal sender, like the <code>kill</code> system call. The signal sent may do something
22441cb0ef41Sopenharmony_ciother than kill the target process.</p>
22451cb0ef41Sopenharmony_ci
22461cb0ef41Sopenharmony_ci<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>;
22471cb0ef41Sopenharmony_ci
22481cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> {
22491cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>);
22501cb0ef41Sopenharmony_ci});
22511cb0ef41Sopenharmony_ci
22521cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
22531cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>);
22541cb0ef41Sopenharmony_ci  process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
22551cb0ef41Sopenharmony_ci}, <span class="hljs-number">100</span>);
22561cb0ef41Sopenharmony_ci
22571cb0ef41Sopenharmony_ci<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>);
22581cb0ef41Sopenharmony_ci
22591cb0ef41Sopenharmony_ciprocess.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> {
22601cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>);
22611cb0ef41Sopenharmony_ci});
22621cb0ef41Sopenharmony_ci
22631cb0ef41Sopenharmony_ci<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
22641cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>);
22651cb0ef41Sopenharmony_ci  process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
22661cb0ef41Sopenharmony_ci}, <span class="hljs-number">100</span>);
22671cb0ef41Sopenharmony_ci
22681cb0ef41Sopenharmony_ciprocess.<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>
22691cb0ef41Sopenharmony_ci<p>When <code>SIGUSR1</code> is received by a Node.js process, Node.js will start the
22701cb0ef41Sopenharmony_cidebugger. See <a href="#signal-events">Signal Events</a>.</p>
22711cb0ef41Sopenharmony_ci</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>
22721cb0ef41Sopenharmony_ci<div class="api_metadata">
22731cb0ef41Sopenharmony_ci<span>Added in: v0.1.17</span><span>Deprecated since: v14.0.0</span>
22741cb0ef41Sopenharmony_ci</div>
22751cb0ef41Sopenharmony_ci<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>
22761cb0ef41Sopenharmony_ci<ul>
22771cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
22781cb0ef41Sopenharmony_ci</ul>
22791cb0ef41Sopenharmony_ci<p>The <code>process.mainModule</code> property provides an alternative way of retrieving
22801cb0ef41Sopenharmony_ci<a href="modules.html#accessing-the-main-module"><code>require.main</code></a>. The difference is that if the main module changes at
22811cb0ef41Sopenharmony_ciruntime, <a href="modules.html#accessing-the-main-module"><code>require.main</code></a> may still refer to the original main module in
22821cb0ef41Sopenharmony_cimodules that were required before the change occurred. Generally, it's
22831cb0ef41Sopenharmony_cisafe to assume that the two refer to the same module.</p>
22841cb0ef41Sopenharmony_ci<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
22851cb0ef41Sopenharmony_ciis no entry script.</p>
22861cb0ef41Sopenharmony_ci</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>
22871cb0ef41Sopenharmony_ci<div class="api_metadata">
22881cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
22891cb0ef41Sopenharmony_ci<table>
22901cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
22911cb0ef41Sopenharmony_ci<tr><td>v13.9.0, v12.17.0</td>
22921cb0ef41Sopenharmony_ci<td><p>Added <code>arrayBuffers</code> to the returned object.</p></td></tr>
22931cb0ef41Sopenharmony_ci<tr><td>v7.2.0</td>
22941cb0ef41Sopenharmony_ci<td><p>Added <code>external</code> to the returned object.</p></td></tr>
22951cb0ef41Sopenharmony_ci<tr><td>v0.1.16</td>
22961cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.16</span></p></td></tr>
22971cb0ef41Sopenharmony_ci</tbody></table>
22981cb0ef41Sopenharmony_ci</details>
22991cb0ef41Sopenharmony_ci</div>
23001cb0ef41Sopenharmony_ci<ul>
23011cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
23021cb0ef41Sopenharmony_ci<ul>
23031cb0ef41Sopenharmony_ci<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>
23041cb0ef41Sopenharmony_ci<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>
23051cb0ef41Sopenharmony_ci<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>
23061cb0ef41Sopenharmony_ci<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>
23071cb0ef41Sopenharmony_ci<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>
23081cb0ef41Sopenharmony_ci</ul>
23091cb0ef41Sopenharmony_ci</li>
23101cb0ef41Sopenharmony_ci</ul>
23111cb0ef41Sopenharmony_ci<p>Returns an object describing the memory usage of the Node.js process measured in
23121cb0ef41Sopenharmony_cibytes.</p>
23131cb0ef41Sopenharmony_ci
23141cb0ef41Sopenharmony_ci<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>;
23151cb0ef41Sopenharmony_ci
23161cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>());
23171cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
23181cb0ef41Sopenharmony_ci<span class="hljs-comment">// {</span>
23191cb0ef41Sopenharmony_ci<span class="hljs-comment">//  rss: 4935680,</span>
23201cb0ef41Sopenharmony_ci<span class="hljs-comment">//  heapTotal: 1826816,</span>
23211cb0ef41Sopenharmony_ci<span class="hljs-comment">//  heapUsed: 650472,</span>
23221cb0ef41Sopenharmony_ci<span class="hljs-comment">//  external: 49879,</span>
23231cb0ef41Sopenharmony_ci<span class="hljs-comment">//  arrayBuffers: 9386</span>
23241cb0ef41Sopenharmony_ci<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>);
23251cb0ef41Sopenharmony_ci
23261cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>());
23271cb0ef41Sopenharmony_ci<span class="hljs-comment">// Prints:</span>
23281cb0ef41Sopenharmony_ci<span class="hljs-comment">// {</span>
23291cb0ef41Sopenharmony_ci<span class="hljs-comment">//  rss: 4935680,</span>
23301cb0ef41Sopenharmony_ci<span class="hljs-comment">//  heapTotal: 1826816,</span>
23311cb0ef41Sopenharmony_ci<span class="hljs-comment">//  heapUsed: 650472,</span>
23321cb0ef41Sopenharmony_ci<span class="hljs-comment">//  external: 49879,</span>
23331cb0ef41Sopenharmony_ci<span class="hljs-comment">//  arrayBuffers: 9386</span>
23341cb0ef41Sopenharmony_ci<span class="hljs-comment">// }</span></code><button class="copy-button">copy</button></pre>
23351cb0ef41Sopenharmony_ci<ul>
23361cb0ef41Sopenharmony_ci<li><code>heapTotal</code> and <code>heapUsed</code> refer to V8's memory usage.</li>
23371cb0ef41Sopenharmony_ci<li><code>external</code> refers to the memory usage of C++ objects bound to JavaScript
23381cb0ef41Sopenharmony_ciobjects managed by V8.</li>
23391cb0ef41Sopenharmony_ci<li><code>rss</code>, Resident Set Size, is the amount of space occupied in the main
23401cb0ef41Sopenharmony_cimemory device (that is a subset of the total allocated memory) for the
23411cb0ef41Sopenharmony_ciprocess, including all C++ and JavaScript objects and code.</li>
23421cb0ef41Sopenharmony_ci<li><code>arrayBuffers</code> refers to memory allocated for <code>ArrayBuffer</code>s and
23431cb0ef41Sopenharmony_ci<code>SharedArrayBuffer</code>s, including all Node.js <a href="buffer.html"><code>Buffer</code></a>s.
23441cb0ef41Sopenharmony_ciThis is also included in the <code>external</code> value. When Node.js is used as an
23451cb0ef41Sopenharmony_ciembedded library, this value may be <code>0</code> because allocations for <code>ArrayBuffer</code>s
23461cb0ef41Sopenharmony_cimay not be tracked in that case.</li>
23471cb0ef41Sopenharmony_ci</ul>
23481cb0ef41Sopenharmony_ci<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
23491cb0ef41Sopenharmony_cientire process, while the other fields will only refer to the current thread.</p>
23501cb0ef41Sopenharmony_ci<p>The <code>process.memoryUsage()</code> method iterates over each page to gather
23511cb0ef41Sopenharmony_ciinformation about memory usage which might be slow depending on the
23521cb0ef41Sopenharmony_ciprogram memory allocations.</p>
23531cb0ef41Sopenharmony_ci</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>
23541cb0ef41Sopenharmony_ci<div class="api_metadata">
23551cb0ef41Sopenharmony_ci<span>Added in: v15.6.0, v14.18.0</span>
23561cb0ef41Sopenharmony_ci</div>
23571cb0ef41Sopenharmony_ci<ul>
23581cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
23591cb0ef41Sopenharmony_ci</ul>
23601cb0ef41Sopenharmony_ci<p>The <code>process.memoryUsage.rss()</code> method returns an integer representing the
23611cb0ef41Sopenharmony_ciResident Set Size (RSS) in bytes.</p>
23621cb0ef41Sopenharmony_ci<p>The Resident Set Size, is the amount of space occupied in the main
23631cb0ef41Sopenharmony_cimemory device (that is a subset of the total allocated memory) for the
23641cb0ef41Sopenharmony_ciprocess, including all C++ and JavaScript objects and code.</p>
23651cb0ef41Sopenharmony_ci<p>This is the same value as the <code>rss</code> property provided by <code>process.memoryUsage()</code>
23661cb0ef41Sopenharmony_cibut <code>process.memoryUsage.rss()</code> is faster.</p>
23671cb0ef41Sopenharmony_ci
23681cb0ef41Sopenharmony_ci<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>;
23691cb0ef41Sopenharmony_ci
23701cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>());
23711cb0ef41Sopenharmony_ci<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>);
23721cb0ef41Sopenharmony_ci
23731cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>());
23741cb0ef41Sopenharmony_ci<span class="hljs-comment">// 35655680</span></code><button class="copy-button">copy</button></pre>
23751cb0ef41Sopenharmony_ci</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>
23761cb0ef41Sopenharmony_ci<div class="api_metadata">
23771cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
23781cb0ef41Sopenharmony_ci<table>
23791cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
23801cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
23811cb0ef41Sopenharmony_ci<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>
23821cb0ef41Sopenharmony_ci<tr><td>v1.8.1</td>
23831cb0ef41Sopenharmony_ci<td><p>Additional arguments after <code>callback</code> are now supported.</p></td></tr>
23841cb0ef41Sopenharmony_ci<tr><td>v0.1.26</td>
23851cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.26</span></p></td></tr>
23861cb0ef41Sopenharmony_ci</tbody></table>
23871cb0ef41Sopenharmony_ci</details>
23881cb0ef41Sopenharmony_ci</div>
23891cb0ef41Sopenharmony_ci<ul>
23901cb0ef41Sopenharmony_ci<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>
23911cb0ef41Sopenharmony_ci<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>
23921cb0ef41Sopenharmony_ci</ul>
23931cb0ef41Sopenharmony_ci<p><code>process.nextTick()</code> adds <code>callback</code> to the "next tick queue". This queue is
23941cb0ef41Sopenharmony_cifully drained after the current operation on the JavaScript stack runs to
23951cb0ef41Sopenharmony_cicompletion and before the event loop is allowed to continue. It's possible to
23961cb0ef41Sopenharmony_cicreate an infinite loop if one were to recursively call <code>process.nextTick()</code>.
23971cb0ef41Sopenharmony_ciSee the <a href="https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick">Event Loop</a> guide for more background.</p>
23981cb0ef41Sopenharmony_ci
23991cb0ef41Sopenharmony_ci<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>;
24001cb0ef41Sopenharmony_ci
24011cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
24021cb0ef41Sopenharmony_ci<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
24031cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick callback'</span>);
24041cb0ef41Sopenharmony_ci});
24051cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
24061cb0ef41Sopenharmony_ci<span class="hljs-comment">// Output:</span>
24071cb0ef41Sopenharmony_ci<span class="hljs-comment">// start</span>
24081cb0ef41Sopenharmony_ci<span class="hljs-comment">// scheduled</span>
24091cb0ef41Sopenharmony_ci<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>);
24101cb0ef41Sopenharmony_ci
24111cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
24121cb0ef41Sopenharmony_ci<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
24131cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick callback'</span>);
24141cb0ef41Sopenharmony_ci});
24151cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
24161cb0ef41Sopenharmony_ci<span class="hljs-comment">// Output:</span>
24171cb0ef41Sopenharmony_ci<span class="hljs-comment">// start</span>
24181cb0ef41Sopenharmony_ci<span class="hljs-comment">// scheduled</span>
24191cb0ef41Sopenharmony_ci<span class="hljs-comment">// nextTick callback</span></code><button class="copy-button">copy</button></pre>
24201cb0ef41Sopenharmony_ci<p>This is important when developing APIs in order to give users the opportunity
24211cb0ef41Sopenharmony_cito assign event handlers <em>after</em> an object has been constructed but before any
24221cb0ef41Sopenharmony_ciI/O has occurred:</p>
24231cb0ef41Sopenharmony_ci
24241cb0ef41Sopenharmony_ci<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>;
24251cb0ef41Sopenharmony_ci
24261cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) {
24271cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options);
24281cb0ef41Sopenharmony_ci
24291cb0ef41Sopenharmony_ci  <span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
24301cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>();
24311cb0ef41Sopenharmony_ci  });
24321cb0ef41Sopenharmony_ci}
24331cb0ef41Sopenharmony_ci
24341cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>();
24351cb0ef41Sopenharmony_cithing.<span class="hljs-title function_">getReadyForStuff</span>();
24361cb0ef41Sopenharmony_ci
24371cb0ef41Sopenharmony_ci<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>);
24381cb0ef41Sopenharmony_ci
24391cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) {
24401cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options);
24411cb0ef41Sopenharmony_ci
24421cb0ef41Sopenharmony_ci  <span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
24431cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>();
24441cb0ef41Sopenharmony_ci  });
24451cb0ef41Sopenharmony_ci}
24461cb0ef41Sopenharmony_ci
24471cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>();
24481cb0ef41Sopenharmony_cithing.<span class="hljs-title function_">getReadyForStuff</span>();
24491cb0ef41Sopenharmony_ci
24501cb0ef41Sopenharmony_ci<span class="hljs-comment">// thing.startDoingStuff() gets called now, not before.</span></code><button class="copy-button">copy</button></pre>
24511cb0ef41Sopenharmony_ci<p>It is very important for APIs to be either 100% synchronous or 100%
24521cb0ef41Sopenharmony_ciasynchronous. Consider this example:</p>
24531cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-comment">// WARNING!  DO NOT USE!  BAD UNSAFE HAZARD!</span>
24541cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">maybeSync</span>(<span class="hljs-params">arg, cb</span>) {
24551cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (arg) {
24561cb0ef41Sopenharmony_ci    <span class="hljs-title function_">cb</span>();
24571cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span>;
24581cb0ef41Sopenharmony_ci  }
24591cb0ef41Sopenharmony_ci
24601cb0ef41Sopenharmony_ci  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
24611cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
24621cb0ef41Sopenharmony_ci<p>This API is hazardous because in the following case:</p>
24631cb0ef41Sopenharmony_ci<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>;
24641cb0ef41Sopenharmony_ci
24651cb0ef41Sopenharmony_ci<span class="hljs-title function_">maybeSync</span>(maybeTrue, <span class="hljs-function">() =></span> {
24661cb0ef41Sopenharmony_ci  <span class="hljs-title function_">foo</span>();
24671cb0ef41Sopenharmony_ci});
24681cb0ef41Sopenharmony_ci
24691cb0ef41Sopenharmony_ci<span class="hljs-title function_">bar</span>();</code> <button class="copy-button">copy</button></pre>
24701cb0ef41Sopenharmony_ci<p>It is not clear whether <code>foo()</code> or <code>bar()</code> will be called first.</p>
24711cb0ef41Sopenharmony_ci<p>The following approach is much better:</p>
24721cb0ef41Sopenharmony_ci
24731cb0ef41Sopenharmony_ci<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>;
24741cb0ef41Sopenharmony_ci
24751cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) {
24761cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (arg) {
24771cb0ef41Sopenharmony_ci    <span class="hljs-title function_">nextTick</span>(cb);
24781cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span>;
24791cb0ef41Sopenharmony_ci  }
24801cb0ef41Sopenharmony_ci
24811cb0ef41Sopenharmony_ci  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
24821cb0ef41Sopenharmony_ci}</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>);
24831cb0ef41Sopenharmony_ci
24841cb0ef41Sopenharmony_ci<span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) {
24851cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (arg) {
24861cb0ef41Sopenharmony_ci    <span class="hljs-title function_">nextTick</span>(cb);
24871cb0ef41Sopenharmony_ci    <span class="hljs-keyword">return</span>;
24881cb0ef41Sopenharmony_ci  }
24891cb0ef41Sopenharmony_ci
24901cb0ef41Sopenharmony_ci  fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
24911cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
24921cb0ef41Sopenharmony_ci<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>
24931cb0ef41Sopenharmony_ci<p>The <a href="globals.html#queuemicrotaskcallback"><code>queueMicrotask()</code></a> API is an alternative to <code>process.nextTick()</code> that
24941cb0ef41Sopenharmony_cialso defers execution of a function using the same microtask queue used to
24951cb0ef41Sopenharmony_ciexecute the then, catch, and finally handlers of resolved promises. Within
24961cb0ef41Sopenharmony_ciNode.js, every time the "next tick queue" is drained, the microtask queue
24971cb0ef41Sopenharmony_ciis drained immediately after.</p>
24981cb0ef41Sopenharmony_ci
24991cb0ef41Sopenharmony_ci<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>;
25001cb0ef41Sopenharmony_ci
25011cb0ef41Sopenharmony_ci<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>));
25021cb0ef41Sopenharmony_ci<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>));
25031cb0ef41Sopenharmony_ci<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>));
25041cb0ef41Sopenharmony_ci<span class="hljs-comment">// Output:</span>
25051cb0ef41Sopenharmony_ci<span class="hljs-comment">// 1</span>
25061cb0ef41Sopenharmony_ci<span class="hljs-comment">// 2</span>
25071cb0ef41Sopenharmony_ci<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>);
25081cb0ef41Sopenharmony_ci
25091cb0ef41Sopenharmony_ci<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>));
25101cb0ef41Sopenharmony_ci<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>));
25111cb0ef41Sopenharmony_ci<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>));
25121cb0ef41Sopenharmony_ci<span class="hljs-comment">// Output:</span>
25131cb0ef41Sopenharmony_ci<span class="hljs-comment">// 1</span>
25141cb0ef41Sopenharmony_ci<span class="hljs-comment">// 2</span>
25151cb0ef41Sopenharmony_ci<span class="hljs-comment">// 3</span></code><button class="copy-button">copy</button></pre>
25161cb0ef41Sopenharmony_ci<p>For <em>most</em> userland use cases, the <code>queueMicrotask()</code> API provides a portable
25171cb0ef41Sopenharmony_ciand reliable mechanism for deferring execution that works across multiple
25181cb0ef41Sopenharmony_ciJavaScript platform environments and should be favored over <code>process.nextTick()</code>.
25191cb0ef41Sopenharmony_ciIn simple scenarios, <code>queueMicrotask()</code> can be a drop-in replacement for
25201cb0ef41Sopenharmony_ci<code>process.nextTick()</code>.</p>
25211cb0ef41Sopenharmony_ci<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>);
25221cb0ef41Sopenharmony_ci<span class="hljs-title function_">queueMicrotask</span>(<span class="hljs-function">() =></span> {
25231cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask callback'</span>);
25241cb0ef41Sopenharmony_ci});
25251cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
25261cb0ef41Sopenharmony_ci<span class="hljs-comment">// Output:</span>
25271cb0ef41Sopenharmony_ci<span class="hljs-comment">// start</span>
25281cb0ef41Sopenharmony_ci<span class="hljs-comment">// scheduled</span>
25291cb0ef41Sopenharmony_ci<span class="hljs-comment">// microtask callback</span></code> <button class="copy-button">copy</button></pre>
25301cb0ef41Sopenharmony_ci<p>One note-worthy difference between the two APIs is that <code>process.nextTick()</code>
25311cb0ef41Sopenharmony_ciallows specifying additional values that will be passed as arguments to the
25321cb0ef41Sopenharmony_cideferred function when it is called. Achieving the same result with
25331cb0ef41Sopenharmony_ci<code>queueMicrotask()</code> requires using either a closure or a bound function:</p>
25341cb0ef41Sopenharmony_ci<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>) {
25351cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask'</span>, a + b);
25361cb0ef41Sopenharmony_ci}
25371cb0ef41Sopenharmony_ci
25381cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
25391cb0ef41Sopenharmony_ci<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>));
25401cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
25411cb0ef41Sopenharmony_ci<span class="hljs-comment">// Output:</span>
25421cb0ef41Sopenharmony_ci<span class="hljs-comment">// start</span>
25431cb0ef41Sopenharmony_ci<span class="hljs-comment">// scheduled</span>
25441cb0ef41Sopenharmony_ci<span class="hljs-comment">// microtask 3</span></code> <button class="copy-button">copy</button></pre>
25451cb0ef41Sopenharmony_ci<p>There are minor differences in the way errors raised from within the next tick
25461cb0ef41Sopenharmony_ciqueue and microtask queue are handled. Errors thrown within a queued microtask
25471cb0ef41Sopenharmony_cicallback should be handled within the queued callback when possible. If they are
25481cb0ef41Sopenharmony_cinot, the <code>process.on('uncaughtException')</code> event handler can be used to capture
25491cb0ef41Sopenharmony_ciand handle the errors.</p>
25501cb0ef41Sopenharmony_ci<p>When in doubt, unless the specific capabilities of <code>process.nextTick()</code> are
25511cb0ef41Sopenharmony_cineeded, use <code>queueMicrotask()</code>.</p>
25521cb0ef41Sopenharmony_ci</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>
25531cb0ef41Sopenharmony_ci<div class="api_metadata">
25541cb0ef41Sopenharmony_ci<span>Added in: v0.8.0</span>
25551cb0ef41Sopenharmony_ci</div>
25561cb0ef41Sopenharmony_ci<ul>
25571cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
25581cb0ef41Sopenharmony_ci</ul>
25591cb0ef41Sopenharmony_ci<p>The <code>process.noDeprecation</code> property indicates whether the <code>--no-deprecation</code>
25601cb0ef41Sopenharmony_ciflag is set on the current Node.js process. See the documentation for
25611cb0ef41Sopenharmony_cithe <a href="#event-warning"><code>'warning'</code> event</a> and the
25621cb0ef41Sopenharmony_ci<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this
25631cb0ef41Sopenharmony_ciflag's behavior.</p>
25641cb0ef41Sopenharmony_ci</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>
25651cb0ef41Sopenharmony_ci<div class="api_metadata">
25661cb0ef41Sopenharmony_ci<span>Added in: v0.1.15</span>
25671cb0ef41Sopenharmony_ci</div>
25681cb0ef41Sopenharmony_ci<ul>
25691cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
25701cb0ef41Sopenharmony_ci</ul>
25711cb0ef41Sopenharmony_ci<p>The <code>process.pid</code> property returns the PID of the process.</p>
25721cb0ef41Sopenharmony_ci
25731cb0ef41Sopenharmony_ci<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>;
25741cb0ef41Sopenharmony_ci
25751cb0ef41Sopenharmony_ci<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>);
25761cb0ef41Sopenharmony_ci
25771cb0ef41Sopenharmony_ci<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>
25781cb0ef41Sopenharmony_ci</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>
25791cb0ef41Sopenharmony_ci<div class="api_metadata">
25801cb0ef41Sopenharmony_ci<span>Added in: v0.1.16</span>
25811cb0ef41Sopenharmony_ci</div>
25821cb0ef41Sopenharmony_ci<ul>
25831cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
25841cb0ef41Sopenharmony_ci</ul>
25851cb0ef41Sopenharmony_ci<p>The <code>process.platform</code> property returns a string identifying the operating
25861cb0ef41Sopenharmony_cisystem platform for which the Node.js binary was compiled.</p>
25871cb0ef41Sopenharmony_ci<p>Currently possible values are:</p>
25881cb0ef41Sopenharmony_ci<ul>
25891cb0ef41Sopenharmony_ci<li><code>'aix'</code></li>
25901cb0ef41Sopenharmony_ci<li><code>'darwin'</code></li>
25911cb0ef41Sopenharmony_ci<li><code>'freebsd'</code></li>
25921cb0ef41Sopenharmony_ci<li><code>'linux'</code></li>
25931cb0ef41Sopenharmony_ci<li><code>'openbsd'</code></li>
25941cb0ef41Sopenharmony_ci<li><code>'sunos'</code></li>
25951cb0ef41Sopenharmony_ci<li><code>'win32'</code></li>
25961cb0ef41Sopenharmony_ci</ul>
25971cb0ef41Sopenharmony_ci
25981cb0ef41Sopenharmony_ci<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>;
25991cb0ef41Sopenharmony_ci
26001cb0ef41Sopenharmony_ci<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>);
26011cb0ef41Sopenharmony_ci
26021cb0ef41Sopenharmony_ci<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>
26031cb0ef41Sopenharmony_ci<p>The value <code>'android'</code> may also be returned if the Node.js is built on the
26041cb0ef41Sopenharmony_ciAndroid operating system. However, Android support in Node.js
26051cb0ef41Sopenharmony_ci<a href="https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os">is experimental</a>.</p>
26061cb0ef41Sopenharmony_ci</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>
26071cb0ef41Sopenharmony_ci<div class="api_metadata">
26081cb0ef41Sopenharmony_ci<span>Added in: v9.2.0, v8.10.0, v6.13.0</span>
26091cb0ef41Sopenharmony_ci</div>
26101cb0ef41Sopenharmony_ci<ul>
26111cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
26121cb0ef41Sopenharmony_ci</ul>
26131cb0ef41Sopenharmony_ci<p>The <code>process.ppid</code> property returns the PID of the parent of the
26141cb0ef41Sopenharmony_cicurrent process.</p>
26151cb0ef41Sopenharmony_ci
26161cb0ef41Sopenharmony_ci<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>;
26171cb0ef41Sopenharmony_ci
26181cb0ef41Sopenharmony_ci<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>);
26191cb0ef41Sopenharmony_ci
26201cb0ef41Sopenharmony_ci<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>
26211cb0ef41Sopenharmony_ci</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>
26221cb0ef41Sopenharmony_ci<div class="api_metadata">
26231cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
26241cb0ef41Sopenharmony_ci<table>
26251cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
26261cb0ef41Sopenharmony_ci<tr><td>v4.2.0</td>
26271cb0ef41Sopenharmony_ci<td><p>The <code>lts</code> property is now supported.</p></td></tr>
26281cb0ef41Sopenharmony_ci<tr><td>v3.0.0</td>
26291cb0ef41Sopenharmony_ci<td><p><span>Added in: v3.0.0</span></p></td></tr>
26301cb0ef41Sopenharmony_ci</tbody></table>
26311cb0ef41Sopenharmony_ci</details>
26321cb0ef41Sopenharmony_ci</div>
26331cb0ef41Sopenharmony_ci<ul>
26341cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
26351cb0ef41Sopenharmony_ci</ul>
26361cb0ef41Sopenharmony_ci<p>The <code>process.release</code> property returns an <code>Object</code> containing metadata related
26371cb0ef41Sopenharmony_cito the current release, including URLs for the source tarball and headers-only
26381cb0ef41Sopenharmony_citarball.</p>
26391cb0ef41Sopenharmony_ci<p><code>process.release</code> contains the following properties:</p>
26401cb0ef41Sopenharmony_ci<ul>
26411cb0ef41Sopenharmony_ci<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>
26421cb0ef41Sopenharmony_ci<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
26431cb0ef41Sopenharmony_cithe source code of the current release.</li>
26441cb0ef41Sopenharmony_ci<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
26451cb0ef41Sopenharmony_cionly the source header files for the current release. This file is
26461cb0ef41Sopenharmony_cisignificantly smaller than the full source file and can be used for compiling
26471cb0ef41Sopenharmony_ciNode.js native add-ons.</li>
26481cb0ef41Sopenharmony_ci<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
26491cb0ef41Sopenharmony_cimatching the architecture and version of the current release. This file is
26501cb0ef41Sopenharmony_ciused for compiling Node.js native add-ons. <em>This property is only present on
26511cb0ef41Sopenharmony_ciWindows builds of Node.js and will be missing on all other platforms.</em></li>
26521cb0ef41Sopenharmony_ci<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
26531cb0ef41Sopenharmony_cirelease. This property only exists for LTS releases and is <code>undefined</code> for all
26541cb0ef41Sopenharmony_ciother release types, including <em>Current</em> releases. Valid values include the
26551cb0ef41Sopenharmony_ciLTS Release code names (including those that are no longer supported).
26561cb0ef41Sopenharmony_ci<ul>
26571cb0ef41Sopenharmony_ci<li><code>'Fermium'</code> for the 14.x LTS line beginning with 14.15.0.</li>
26581cb0ef41Sopenharmony_ci<li><code>'Gallium'</code> for the 16.x LTS line beginning with 16.13.0.</li>
26591cb0ef41Sopenharmony_ci<li><code>'Hydrogen'</code> for the 18.x LTS line beginning with 18.12.0.
26601cb0ef41Sopenharmony_ciFor 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>
26611cb0ef41Sopenharmony_ci</ul>
26621cb0ef41Sopenharmony_ci</li>
26631cb0ef41Sopenharmony_ci</ul>
26641cb0ef41Sopenharmony_ci<!-- eslint-skip -->
26651cb0ef41Sopenharmony_ci<pre><code class="language-js">{
26661cb0ef41Sopenharmony_ci  <span class="hljs-attr">name</span>: <span class="hljs-string">'node'</span>,
26671cb0ef41Sopenharmony_ci  <span class="hljs-attr">lts</span>: <span class="hljs-string">'Hydrogen'</span>,
26681cb0ef41Sopenharmony_ci  <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>,
26691cb0ef41Sopenharmony_ci  <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>,
26701cb0ef41Sopenharmony_ci  <span class="hljs-attr">libUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/win-x64/node.lib'</span>
26711cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
26721cb0ef41Sopenharmony_ci<p>In custom builds from non-release versions of the source tree, only the
26731cb0ef41Sopenharmony_ci<code>name</code> property may be present. The additional properties should not be
26741cb0ef41Sopenharmony_cirelied upon to exist.</p>
26751cb0ef41Sopenharmony_ci</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>
26761cb0ef41Sopenharmony_ci<div class="api_metadata">
26771cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
26781cb0ef41Sopenharmony_ci<table>
26791cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
26801cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
26811cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
26821cb0ef41Sopenharmony_ci<tr><td>v11.8.0</td>
26831cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.8.0</span></p></td></tr>
26841cb0ef41Sopenharmony_ci</tbody></table>
26851cb0ef41Sopenharmony_ci</details>
26861cb0ef41Sopenharmony_ci</div>
26871cb0ef41Sopenharmony_ci<ul>
26881cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
26891cb0ef41Sopenharmony_ci</ul>
26901cb0ef41Sopenharmony_ci<p><code>process.report</code> is an object whose methods are used to generate diagnostic
26911cb0ef41Sopenharmony_cireports for the current process. Additional documentation is available in the
26921cb0ef41Sopenharmony_ci<a href="report.html">report documentation</a>.</p>
26931cb0ef41Sopenharmony_ci<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>
26941cb0ef41Sopenharmony_ci<div class="api_metadata">
26951cb0ef41Sopenharmony_ci<span>Added in: v13.12.0, v12.17.0</span>
26961cb0ef41Sopenharmony_ci</div>
26971cb0ef41Sopenharmony_ci<ul>
26981cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
26991cb0ef41Sopenharmony_ci</ul>
27001cb0ef41Sopenharmony_ci<p>Write reports in a compact format, single-line JSON, more easily consumable
27011cb0ef41Sopenharmony_ciby log processing systems than the default multi-line format designed for
27021cb0ef41Sopenharmony_cihuman consumption.</p>
27031cb0ef41Sopenharmony_ci
27041cb0ef41Sopenharmony_ci<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>;
27051cb0ef41Sopenharmony_ci
27061cb0ef41Sopenharmony_ci<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>);
27071cb0ef41Sopenharmony_ci
27081cb0ef41Sopenharmony_ci<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>
27091cb0ef41Sopenharmony_ci<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>
27101cb0ef41Sopenharmony_ci<div class="api_metadata">
27111cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
27121cb0ef41Sopenharmony_ci<table>
27131cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
27141cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
27151cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
27161cb0ef41Sopenharmony_ci<tr><td>v11.12.0</td>
27171cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.12.0</span></p></td></tr>
27181cb0ef41Sopenharmony_ci</tbody></table>
27191cb0ef41Sopenharmony_ci</details>
27201cb0ef41Sopenharmony_ci</div>
27211cb0ef41Sopenharmony_ci<ul>
27221cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
27231cb0ef41Sopenharmony_ci</ul>
27241cb0ef41Sopenharmony_ci<p>Directory where the report is written. The default value is the empty string,
27251cb0ef41Sopenharmony_ciindicating that reports are written to the current working directory of the
27261cb0ef41Sopenharmony_ciNode.js process.</p>
27271cb0ef41Sopenharmony_ci
27281cb0ef41Sopenharmony_ci<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>;
27291cb0ef41Sopenharmony_ci
27301cb0ef41Sopenharmony_ci<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>);
27311cb0ef41Sopenharmony_ci
27321cb0ef41Sopenharmony_ci<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>
27331cb0ef41Sopenharmony_ci<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>
27341cb0ef41Sopenharmony_ci<div class="api_metadata">
27351cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
27361cb0ef41Sopenharmony_ci<table>
27371cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
27381cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
27391cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
27401cb0ef41Sopenharmony_ci<tr><td>v11.12.0</td>
27411cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.12.0</span></p></td></tr>
27421cb0ef41Sopenharmony_ci</tbody></table>
27431cb0ef41Sopenharmony_ci</details>
27441cb0ef41Sopenharmony_ci</div>
27451cb0ef41Sopenharmony_ci<ul>
27461cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
27471cb0ef41Sopenharmony_ci</ul>
27481cb0ef41Sopenharmony_ci<p>Filename where the report is written. If set to the empty string, the output
27491cb0ef41Sopenharmony_cifilename will be comprised of a timestamp, PID, and sequence number. The default
27501cb0ef41Sopenharmony_civalue is the empty string.</p>
27511cb0ef41Sopenharmony_ci<p>If the value of <code>process.report.filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>,
27521cb0ef41Sopenharmony_cithe report is written to the stdout or stderr of the process respectively.</p>
27531cb0ef41Sopenharmony_ci
27541cb0ef41Sopenharmony_ci<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>;
27551cb0ef41Sopenharmony_ci
27561cb0ef41Sopenharmony_ci<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>);
27571cb0ef41Sopenharmony_ci
27581cb0ef41Sopenharmony_ci<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>
27591cb0ef41Sopenharmony_ci<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>
27601cb0ef41Sopenharmony_ci<div class="api_metadata">
27611cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
27621cb0ef41Sopenharmony_ci<table>
27631cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
27641cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
27651cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
27661cb0ef41Sopenharmony_ci<tr><td>v11.8.0</td>
27671cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.8.0</span></p></td></tr>
27681cb0ef41Sopenharmony_ci</tbody></table>
27691cb0ef41Sopenharmony_ci</details>
27701cb0ef41Sopenharmony_ci</div>
27711cb0ef41Sopenharmony_ci<ul>
27721cb0ef41Sopenharmony_ci<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>
27731cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
27741cb0ef41Sopenharmony_ci</ul>
27751cb0ef41Sopenharmony_ci<p>Returns a JavaScript Object representation of a diagnostic report for the
27761cb0ef41Sopenharmony_cirunning process. The report's JavaScript stack trace is taken from <code>err</code>, if
27771cb0ef41Sopenharmony_cipresent.</p>
27781cb0ef41Sopenharmony_ci
27791cb0ef41Sopenharmony_ci<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>;
27801cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> util <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
27811cb0ef41Sopenharmony_ci
27821cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>();
27831cb0ef41Sopenharmony_ci<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>);
27841cb0ef41Sopenharmony_ci
27851cb0ef41Sopenharmony_ci<span class="hljs-comment">// Similar to process.report.writeReport()</span>
27861cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> fs <span class="hljs-keyword">from</span> <span class="hljs-string">'node:fs'</span>;
27871cb0ef41Sopenharmony_cifs.<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>);
27881cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
27891cb0ef41Sopenharmony_ci
27901cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>();
27911cb0ef41Sopenharmony_ci<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>);
27921cb0ef41Sopenharmony_ci
27931cb0ef41Sopenharmony_ci<span class="hljs-comment">// Similar to process.report.writeReport()</span>
27941cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
27951cb0ef41Sopenharmony_cifs.<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>
27961cb0ef41Sopenharmony_ci<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
27971cb0ef41Sopenharmony_ci<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>
27981cb0ef41Sopenharmony_ci<div class="api_metadata">
27991cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
28001cb0ef41Sopenharmony_ci<table>
28011cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
28021cb0ef41Sopenharmony_ci<tr><td>v15.0.0, v14.17.0</td>
28031cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
28041cb0ef41Sopenharmony_ci<tr><td>v11.12.0</td>
28051cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.12.0</span></p></td></tr>
28061cb0ef41Sopenharmony_ci</tbody></table>
28071cb0ef41Sopenharmony_ci</details>
28081cb0ef41Sopenharmony_ci</div>
28091cb0ef41Sopenharmony_ci<ul>
28101cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28111cb0ef41Sopenharmony_ci</ul>
28121cb0ef41Sopenharmony_ci<p>If <code>true</code>, a diagnostic report is generated on fatal errors, such as out of
28131cb0ef41Sopenharmony_cimemory errors or failed C++ assertions.</p>
28141cb0ef41Sopenharmony_ci
28151cb0ef41Sopenharmony_ci<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>;
28161cb0ef41Sopenharmony_ci
28171cb0ef41Sopenharmony_ci<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>);
28181cb0ef41Sopenharmony_ci
28191cb0ef41Sopenharmony_ci<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>
28201cb0ef41Sopenharmony_ci<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>
28211cb0ef41Sopenharmony_ci<div class="api_metadata">
28221cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
28231cb0ef41Sopenharmony_ci<table>
28241cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
28251cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
28261cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
28271cb0ef41Sopenharmony_ci<tr><td>v11.12.0</td>
28281cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.12.0</span></p></td></tr>
28291cb0ef41Sopenharmony_ci</tbody></table>
28301cb0ef41Sopenharmony_ci</details>
28311cb0ef41Sopenharmony_ci</div>
28321cb0ef41Sopenharmony_ci<ul>
28331cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28341cb0ef41Sopenharmony_ci</ul>
28351cb0ef41Sopenharmony_ci<p>If <code>true</code>, a diagnostic report is generated when the process receives the
28361cb0ef41Sopenharmony_cisignal specified by <code>process.report.signal</code>.</p>
28371cb0ef41Sopenharmony_ci
28381cb0ef41Sopenharmony_ci<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>;
28391cb0ef41Sopenharmony_ci
28401cb0ef41Sopenharmony_ci<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>);
28411cb0ef41Sopenharmony_ci
28421cb0ef41Sopenharmony_ci<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>
28431cb0ef41Sopenharmony_ci<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>
28441cb0ef41Sopenharmony_ci<div class="api_metadata">
28451cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
28461cb0ef41Sopenharmony_ci<table>
28471cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
28481cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
28491cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
28501cb0ef41Sopenharmony_ci<tr><td>v11.12.0</td>
28511cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.12.0</span></p></td></tr>
28521cb0ef41Sopenharmony_ci</tbody></table>
28531cb0ef41Sopenharmony_ci</details>
28541cb0ef41Sopenharmony_ci</div>
28551cb0ef41Sopenharmony_ci<ul>
28561cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
28571cb0ef41Sopenharmony_ci</ul>
28581cb0ef41Sopenharmony_ci<p>If <code>true</code>, a diagnostic report is generated on uncaught exception.</p>
28591cb0ef41Sopenharmony_ci
28601cb0ef41Sopenharmony_ci<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>;
28611cb0ef41Sopenharmony_ci
28621cb0ef41Sopenharmony_ci<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>);
28631cb0ef41Sopenharmony_ci
28641cb0ef41Sopenharmony_ci<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>
28651cb0ef41Sopenharmony_ci<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>
28661cb0ef41Sopenharmony_ci<div class="api_metadata">
28671cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
28681cb0ef41Sopenharmony_ci<table>
28691cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
28701cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
28711cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
28721cb0ef41Sopenharmony_ci<tr><td>v11.12.0</td>
28731cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.12.0</span></p></td></tr>
28741cb0ef41Sopenharmony_ci</tbody></table>
28751cb0ef41Sopenharmony_ci</details>
28761cb0ef41Sopenharmony_ci</div>
28771cb0ef41Sopenharmony_ci<ul>
28781cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
28791cb0ef41Sopenharmony_ci</ul>
28801cb0ef41Sopenharmony_ci<p>The signal used to trigger the creation of a diagnostic report. Defaults to
28811cb0ef41Sopenharmony_ci<code>'SIGUSR2'</code>.</p>
28821cb0ef41Sopenharmony_ci
28831cb0ef41Sopenharmony_ci<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>;
28841cb0ef41Sopenharmony_ci
28851cb0ef41Sopenharmony_ci<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>);
28861cb0ef41Sopenharmony_ci
28871cb0ef41Sopenharmony_ci<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>
28881cb0ef41Sopenharmony_ci<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>
28891cb0ef41Sopenharmony_ci<div class="api_metadata">
28901cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
28911cb0ef41Sopenharmony_ci<table>
28921cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
28931cb0ef41Sopenharmony_ci<tr><td>v13.12.0, v12.17.0</td>
28941cb0ef41Sopenharmony_ci<td><p>This API is no longer experimental.</p></td></tr>
28951cb0ef41Sopenharmony_ci<tr><td>v11.8.0</td>
28961cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.8.0</span></p></td></tr>
28971cb0ef41Sopenharmony_ci</tbody></table>
28981cb0ef41Sopenharmony_ci</details>
28991cb0ef41Sopenharmony_ci</div>
29001cb0ef41Sopenharmony_ci<ul>
29011cb0ef41Sopenharmony_ci<li>
29021cb0ef41Sopenharmony_ci<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
29031cb0ef41Sopenharmony_cishould be a relative path, that will be appended to the directory specified in
29041cb0ef41Sopenharmony_ci<code>process.report.directory</code>, or the current working directory of the Node.js
29051cb0ef41Sopenharmony_ciprocess, if unspecified.</p>
29061cb0ef41Sopenharmony_ci</li>
29071cb0ef41Sopenharmony_ci<li>
29081cb0ef41Sopenharmony_ci<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>
29091cb0ef41Sopenharmony_ci</li>
29101cb0ef41Sopenharmony_ci<li>
29111cb0ef41Sopenharmony_ci<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>
29121cb0ef41Sopenharmony_ci</li>
29131cb0ef41Sopenharmony_ci</ul>
29141cb0ef41Sopenharmony_ci<p>Writes a diagnostic report to a file. If <code>filename</code> is not provided, the default
29151cb0ef41Sopenharmony_cifilename includes the date, time, PID, and a sequence number. The report's
29161cb0ef41Sopenharmony_ciJavaScript stack trace is taken from <code>err</code>, if present.</p>
29171cb0ef41Sopenharmony_ci<p>If the value of <code>filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>, the report is
29181cb0ef41Sopenharmony_ciwritten to the stdout or stderr of the process respectively.</p>
29191cb0ef41Sopenharmony_ci
29201cb0ef41Sopenharmony_ci<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>;
29211cb0ef41Sopenharmony_ci
29221cb0ef41Sopenharmony_cireport.<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>);
29231cb0ef41Sopenharmony_ci
29241cb0ef41Sopenharmony_cireport.<span class="hljs-title function_">writeReport</span>();</code><button class="copy-button">copy</button></pre>
29251cb0ef41Sopenharmony_ci<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
29261cb0ef41Sopenharmony_ci</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>
29271cb0ef41Sopenharmony_ci<div class="api_metadata">
29281cb0ef41Sopenharmony_ci<span>Added in: v12.6.0</span>
29291cb0ef41Sopenharmony_ci</div>
29301cb0ef41Sopenharmony_ci<ul>
29311cb0ef41Sopenharmony_ci<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
29321cb0ef41Sopenharmony_civalues come from the <code>uv_getrusage</code> call which returns
29331cb0ef41Sopenharmony_cia <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t"><code>uv_rusage_t</code> struct</a>.
29341cb0ef41Sopenharmony_ci<ul>
29351cb0ef41Sopenharmony_ci<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.
29361cb0ef41Sopenharmony_ciIt is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().user</code></a>.</li>
29371cb0ef41Sopenharmony_ci<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.
29381cb0ef41Sopenharmony_ciIt is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().system</code></a>.</li>
29391cb0ef41Sopenharmony_ci<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
29401cb0ef41Sopenharmony_cisize used in kilobytes.</li>
29411cb0ef41Sopenharmony_ci<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
29421cb0ef41Sopenharmony_ciany platform.</li>
29431cb0ef41Sopenharmony_ci<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
29441cb0ef41Sopenharmony_ciany platform.</li>
29451cb0ef41Sopenharmony_ci<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
29461cb0ef41Sopenharmony_ciany platform.</li>
29471cb0ef41Sopenharmony_ci<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
29481cb0ef41Sopenharmony_ciminor page faults for the process, see
29491cb0ef41Sopenharmony_ci<a href="https://en.wikipedia.org/wiki/Page_fault#Minor">this article for more details</a>.</li>
29501cb0ef41Sopenharmony_ci<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
29511cb0ef41Sopenharmony_cimajor page faults for the process, see
29521cb0ef41Sopenharmony_ci<a href="https://en.wikipedia.org/wiki/Page_fault#Major">this article for more details</a>. This field is not
29531cb0ef41Sopenharmony_cisupported on Windows.</li>
29541cb0ef41Sopenharmony_ci<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
29551cb0ef41Sopenharmony_ciplatform.</li>
29561cb0ef41Sopenharmony_ci<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
29571cb0ef41Sopenharmony_cifile system had to perform input.</li>
29581cb0ef41Sopenharmony_ci<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
29591cb0ef41Sopenharmony_cifile system had to perform output.</li>
29601cb0ef41Sopenharmony_ci<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
29611cb0ef41Sopenharmony_ciplatform.</li>
29621cb0ef41Sopenharmony_ci<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
29631cb0ef41Sopenharmony_ciplatform.</li>
29641cb0ef41Sopenharmony_ci<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
29651cb0ef41Sopenharmony_ciplatform.</li>
29661cb0ef41Sopenharmony_ci<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
29671cb0ef41Sopenharmony_cinumber of times a CPU context switch resulted due to a process voluntarily
29681cb0ef41Sopenharmony_cigiving up the processor before its time slice was completed (usually to
29691cb0ef41Sopenharmony_ciawait availability of a resource). This field is not supported on Windows.</li>
29701cb0ef41Sopenharmony_ci<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
29711cb0ef41Sopenharmony_cinumber of times a CPU context switch resulted due to a higher priority
29721cb0ef41Sopenharmony_ciprocess becoming runnable or because the current process exceeded its
29731cb0ef41Sopenharmony_citime slice. This field is not supported on Windows.</li>
29741cb0ef41Sopenharmony_ci</ul>
29751cb0ef41Sopenharmony_ci</li>
29761cb0ef41Sopenharmony_ci</ul>
29771cb0ef41Sopenharmony_ci
29781cb0ef41Sopenharmony_ci<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>;
29791cb0ef41Sopenharmony_ci
29801cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>());
29811cb0ef41Sopenharmony_ci<span class="hljs-comment">/*
29821cb0ef41Sopenharmony_ci  Will output:
29831cb0ef41Sopenharmony_ci  {
29841cb0ef41Sopenharmony_ci    userCPUTime: 82872,
29851cb0ef41Sopenharmony_ci    systemCPUTime: 4143,
29861cb0ef41Sopenharmony_ci    maxRSS: 33164,
29871cb0ef41Sopenharmony_ci    sharedMemorySize: 0,
29881cb0ef41Sopenharmony_ci    unsharedDataSize: 0,
29891cb0ef41Sopenharmony_ci    unsharedStackSize: 0,
29901cb0ef41Sopenharmony_ci    minorPageFault: 2469,
29911cb0ef41Sopenharmony_ci    majorPageFault: 0,
29921cb0ef41Sopenharmony_ci    swappedOut: 0,
29931cb0ef41Sopenharmony_ci    fsRead: 0,
29941cb0ef41Sopenharmony_ci    fsWrite: 8,
29951cb0ef41Sopenharmony_ci    ipcSent: 0,
29961cb0ef41Sopenharmony_ci    ipcReceived: 0,
29971cb0ef41Sopenharmony_ci    signalsCount: 0,
29981cb0ef41Sopenharmony_ci    voluntaryContextSwitches: 79,
29991cb0ef41Sopenharmony_ci    involuntaryContextSwitches: 1
30001cb0ef41Sopenharmony_ci  }
30011cb0ef41Sopenharmony_ci*/</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>);
30021cb0ef41Sopenharmony_ci
30031cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>());
30041cb0ef41Sopenharmony_ci<span class="hljs-comment">/*
30051cb0ef41Sopenharmony_ci  Will output:
30061cb0ef41Sopenharmony_ci  {
30071cb0ef41Sopenharmony_ci    userCPUTime: 82872,
30081cb0ef41Sopenharmony_ci    systemCPUTime: 4143,
30091cb0ef41Sopenharmony_ci    maxRSS: 33164,
30101cb0ef41Sopenharmony_ci    sharedMemorySize: 0,
30111cb0ef41Sopenharmony_ci    unsharedDataSize: 0,
30121cb0ef41Sopenharmony_ci    unsharedStackSize: 0,
30131cb0ef41Sopenharmony_ci    minorPageFault: 2469,
30141cb0ef41Sopenharmony_ci    majorPageFault: 0,
30151cb0ef41Sopenharmony_ci    swappedOut: 0,
30161cb0ef41Sopenharmony_ci    fsRead: 0,
30171cb0ef41Sopenharmony_ci    fsWrite: 8,
30181cb0ef41Sopenharmony_ci    ipcSent: 0,
30191cb0ef41Sopenharmony_ci    ipcReceived: 0,
30201cb0ef41Sopenharmony_ci    signalsCount: 0,
30211cb0ef41Sopenharmony_ci    voluntaryContextSwitches: 79,
30221cb0ef41Sopenharmony_ci    involuntaryContextSwitches: 1
30231cb0ef41Sopenharmony_ci  }
30241cb0ef41Sopenharmony_ci*/</span></code><button class="copy-button">copy</button></pre>
30251cb0ef41Sopenharmony_ci</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>
30261cb0ef41Sopenharmony_ci<div class="api_metadata">
30271cb0ef41Sopenharmony_ci<span>Added in: v0.5.9</span>
30281cb0ef41Sopenharmony_ci</div>
30291cb0ef41Sopenharmony_ci<ul>
30301cb0ef41Sopenharmony_ci<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>
30311cb0ef41Sopenharmony_ci<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>
30321cb0ef41Sopenharmony_ci<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
30331cb0ef41Sopenharmony_cihandles.<code>options</code> supports the following properties:
30341cb0ef41Sopenharmony_ci<ul>
30351cb0ef41Sopenharmony_ci<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
30361cb0ef41Sopenharmony_ci<code>net.Socket</code>. When <code>true</code>, the socket is kept open in the sending process.
30371cb0ef41Sopenharmony_ci<strong>Default:</strong> <code>false</code>.</li>
30381cb0ef41Sopenharmony_ci</ul>
30391cb0ef41Sopenharmony_ci</li>
30401cb0ef41Sopenharmony_ci<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>
30411cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
30421cb0ef41Sopenharmony_ci</ul>
30431cb0ef41Sopenharmony_ci<p>If Node.js is spawned with an IPC channel, the <code>process.send()</code> method can be
30441cb0ef41Sopenharmony_ciused to send messages to the parent process. Messages will be received as a
30451cb0ef41Sopenharmony_ci<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>
30461cb0ef41Sopenharmony_ci<p>If Node.js was not spawned with an IPC channel, <code>process.send</code> will be
30471cb0ef41Sopenharmony_ci<code>undefined</code>.</p>
30481cb0ef41Sopenharmony_ci<p>The message goes through serialization and parsing. The resulting message might
30491cb0ef41Sopenharmony_cinot be the same as what is originally sent.</p>
30501cb0ef41Sopenharmony_ci</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>
30511cb0ef41Sopenharmony_ci<div class="api_metadata">
30521cb0ef41Sopenharmony_ci<span>Added in: v2.0.0</span>
30531cb0ef41Sopenharmony_ci</div>
30541cb0ef41Sopenharmony_ci<ul>
30551cb0ef41Sopenharmony_ci<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>
30561cb0ef41Sopenharmony_ci</ul>
30571cb0ef41Sopenharmony_ci<p>The <code>process.setegid()</code> method sets the effective group identity of the process.
30581cb0ef41Sopenharmony_ci(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
30591cb0ef41Sopenharmony_ciname string. If a group name is specified, this method blocks while resolving
30601cb0ef41Sopenharmony_cithe associated a numeric ID.</p>
30611cb0ef41Sopenharmony_ci
30621cb0ef41Sopenharmony_ci<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>;
30631cb0ef41Sopenharmony_ci
30641cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> &#x26;&#x26; process.<span class="hljs-property">setegid</span>) {
30651cb0ef41Sopenharmony_ci  <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>);
30661cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
30671cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>);
30681cb0ef41Sopenharmony_ci    <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>);
30691cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
30701cb0ef41Sopenharmony_ci    <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>);
30711cb0ef41Sopenharmony_ci  }
30721cb0ef41Sopenharmony_ci}</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>);
30731cb0ef41Sopenharmony_ci
30741cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> &#x26;&#x26; process.<span class="hljs-property">setegid</span>) {
30751cb0ef41Sopenharmony_ci  <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>);
30761cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
30771cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>);
30781cb0ef41Sopenharmony_ci    <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>);
30791cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
30801cb0ef41Sopenharmony_ci    <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>);
30811cb0ef41Sopenharmony_ci  }
30821cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
30831cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
30841cb0ef41Sopenharmony_ciAndroid).
30851cb0ef41Sopenharmony_ciThis feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
30861cb0ef41Sopenharmony_ci</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>
30871cb0ef41Sopenharmony_ci<div class="api_metadata">
30881cb0ef41Sopenharmony_ci<span>Added in: v2.0.0</span>
30891cb0ef41Sopenharmony_ci</div>
30901cb0ef41Sopenharmony_ci<ul>
30911cb0ef41Sopenharmony_ci<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>
30921cb0ef41Sopenharmony_ci</ul>
30931cb0ef41Sopenharmony_ci<p>The <code>process.seteuid()</code> method sets the effective user identity of the process.
30941cb0ef41Sopenharmony_ci(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
30951cb0ef41Sopenharmony_cistring. If a username is specified, the method blocks while resolving the
30961cb0ef41Sopenharmony_ciassociated numeric ID.</p>
30971cb0ef41Sopenharmony_ci
30981cb0ef41Sopenharmony_ci<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>;
30991cb0ef41Sopenharmony_ci
31001cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> &#x26;&#x26; process.<span class="hljs-property">seteuid</span>) {
31011cb0ef41Sopenharmony_ci  <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>);
31021cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
31031cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>);
31041cb0ef41Sopenharmony_ci    <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>);
31051cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
31061cb0ef41Sopenharmony_ci    <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>);
31071cb0ef41Sopenharmony_ci  }
31081cb0ef41Sopenharmony_ci}</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>);
31091cb0ef41Sopenharmony_ci
31101cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> &#x26;&#x26; process.<span class="hljs-property">seteuid</span>) {
31111cb0ef41Sopenharmony_ci  <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>);
31121cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
31131cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>);
31141cb0ef41Sopenharmony_ci    <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>);
31151cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
31161cb0ef41Sopenharmony_ci    <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>);
31171cb0ef41Sopenharmony_ci  }
31181cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
31191cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
31201cb0ef41Sopenharmony_ciAndroid).
31211cb0ef41Sopenharmony_ciThis feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
31221cb0ef41Sopenharmony_ci</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>
31231cb0ef41Sopenharmony_ci<div class="api_metadata">
31241cb0ef41Sopenharmony_ci<span>Added in: v0.1.31</span>
31251cb0ef41Sopenharmony_ci</div>
31261cb0ef41Sopenharmony_ci<ul>
31271cb0ef41Sopenharmony_ci<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>
31281cb0ef41Sopenharmony_ci</ul>
31291cb0ef41Sopenharmony_ci<p>The <code>process.setgid()</code> method sets the group identity of the process. (See
31301cb0ef41Sopenharmony_ci<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
31311cb0ef41Sopenharmony_cistring. If a group name is specified, this method blocks while resolving the
31321cb0ef41Sopenharmony_ciassociated numeric ID.</p>
31331cb0ef41Sopenharmony_ci
31341cb0ef41Sopenharmony_ci<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>;
31351cb0ef41Sopenharmony_ci
31361cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> &#x26;&#x26; process.<span class="hljs-property">setgid</span>) {
31371cb0ef41Sopenharmony_ci  <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>);
31381cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
31391cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>);
31401cb0ef41Sopenharmony_ci    <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>);
31411cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
31421cb0ef41Sopenharmony_ci    <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>);
31431cb0ef41Sopenharmony_ci  }
31441cb0ef41Sopenharmony_ci}</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>);
31451cb0ef41Sopenharmony_ci
31461cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> &#x26;&#x26; process.<span class="hljs-property">setgid</span>) {
31471cb0ef41Sopenharmony_ci  <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>);
31481cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
31491cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>);
31501cb0ef41Sopenharmony_ci    <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>);
31511cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
31521cb0ef41Sopenharmony_ci    <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>);
31531cb0ef41Sopenharmony_ci  }
31541cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
31551cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
31561cb0ef41Sopenharmony_ciAndroid).
31571cb0ef41Sopenharmony_ciThis feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
31581cb0ef41Sopenharmony_ci</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>
31591cb0ef41Sopenharmony_ci<div class="api_metadata">
31601cb0ef41Sopenharmony_ci<span>Added in: v0.9.4</span>
31611cb0ef41Sopenharmony_ci</div>
31621cb0ef41Sopenharmony_ci<ul>
31631cb0ef41Sopenharmony_ci<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>
31641cb0ef41Sopenharmony_ci</ul>
31651cb0ef41Sopenharmony_ci<p>The <code>process.setgroups()</code> method sets the supplementary group IDs for the
31661cb0ef41Sopenharmony_ciNode.js process. This is a privileged operation that requires the Node.js
31671cb0ef41Sopenharmony_ciprocess to have <code>root</code> or the <code>CAP_SETGID</code> capability.</p>
31681cb0ef41Sopenharmony_ci<p>The <code>groups</code> array can contain numeric group IDs, group names, or both.</p>
31691cb0ef41Sopenharmony_ci
31701cb0ef41Sopenharmony_ci<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>;
31711cb0ef41Sopenharmony_ci
31721cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> &#x26;&#x26; process.<span class="hljs-property">setgroups</span>) {
31731cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
31741cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]);
31751cb0ef41Sopenharmony_ci    <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>
31761cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
31771cb0ef41Sopenharmony_ci    <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>);
31781cb0ef41Sopenharmony_ci  }
31791cb0ef41Sopenharmony_ci}</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>);
31801cb0ef41Sopenharmony_ci
31811cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> &#x26;&#x26; process.<span class="hljs-property">setgroups</span>) {
31821cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
31831cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]);
31841cb0ef41Sopenharmony_ci    <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>
31851cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
31861cb0ef41Sopenharmony_ci    <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>);
31871cb0ef41Sopenharmony_ci  }
31881cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
31891cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
31901cb0ef41Sopenharmony_ciAndroid).
31911cb0ef41Sopenharmony_ciThis feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
31921cb0ef41Sopenharmony_ci</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>
31931cb0ef41Sopenharmony_ci<div class="api_metadata">
31941cb0ef41Sopenharmony_ci<span>Added in: v0.1.28</span>
31951cb0ef41Sopenharmony_ci</div>
31961cb0ef41Sopenharmony_ci<ul>
31971cb0ef41Sopenharmony_ci<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>
31981cb0ef41Sopenharmony_ci</ul>
31991cb0ef41Sopenharmony_ci<p>The <code>process.setuid(id)</code> method sets the user identity of the process. (See
32001cb0ef41Sopenharmony_ci<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.
32011cb0ef41Sopenharmony_ciIf a username is specified, the method blocks while resolving the associated
32021cb0ef41Sopenharmony_cinumeric ID.</p>
32031cb0ef41Sopenharmony_ci
32041cb0ef41Sopenharmony_ci<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>;
32051cb0ef41Sopenharmony_ci
32061cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> &#x26;&#x26; process.<span class="hljs-property">setuid</span>) {
32071cb0ef41Sopenharmony_ci  <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>);
32081cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
32091cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>);
32101cb0ef41Sopenharmony_ci    <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>);
32111cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
32121cb0ef41Sopenharmony_ci    <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>);
32131cb0ef41Sopenharmony_ci  }
32141cb0ef41Sopenharmony_ci}</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>);
32151cb0ef41Sopenharmony_ci
32161cb0ef41Sopenharmony_ci<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> &#x26;&#x26; process.<span class="hljs-property">setuid</span>) {
32171cb0ef41Sopenharmony_ci  <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>);
32181cb0ef41Sopenharmony_ci  <span class="hljs-keyword">try</span> {
32191cb0ef41Sopenharmony_ci    process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>);
32201cb0ef41Sopenharmony_ci    <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>);
32211cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">catch</span> (err) {
32221cb0ef41Sopenharmony_ci    <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>);
32231cb0ef41Sopenharmony_ci  }
32241cb0ef41Sopenharmony_ci}</code><button class="copy-button">copy</button></pre>
32251cb0ef41Sopenharmony_ci<p>This function is only available on POSIX platforms (i.e. not Windows or
32261cb0ef41Sopenharmony_ciAndroid).
32271cb0ef41Sopenharmony_ciThis feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
32281cb0ef41Sopenharmony_ci</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>
32291cb0ef41Sopenharmony_ci<div class="api_metadata">
32301cb0ef41Sopenharmony_ci<span>Added in: v16.6.0, v14.18.0</span>
32311cb0ef41Sopenharmony_ci</div>
32321cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
32331cb0ef41Sopenharmony_ci<ul>
32341cb0ef41Sopenharmony_ci<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>
32351cb0ef41Sopenharmony_ci</ul>
32361cb0ef41Sopenharmony_ci<p>This function enables or disables the <a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for
32371cb0ef41Sopenharmony_cistack traces.</p>
32381cb0ef41Sopenharmony_ci<p>It provides same features as launching Node.js process with commandline options
32391cb0ef41Sopenharmony_ci<code>--enable-source-maps</code>.</p>
32401cb0ef41Sopenharmony_ci<p>Only source maps in JavaScript files that are loaded after source maps has been
32411cb0ef41Sopenharmony_cienabled will be parsed and loaded.</p>
32421cb0ef41Sopenharmony_ci</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>
32431cb0ef41Sopenharmony_ci<div class="api_metadata">
32441cb0ef41Sopenharmony_ci<span>Added in: v9.3.0</span>
32451cb0ef41Sopenharmony_ci</div>
32461cb0ef41Sopenharmony_ci<ul>
32471cb0ef41Sopenharmony_ci<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>
32481cb0ef41Sopenharmony_ci</ul>
32491cb0ef41Sopenharmony_ci<p>The <code>process.setUncaughtExceptionCaptureCallback()</code> function sets a function
32501cb0ef41Sopenharmony_cithat will be invoked when an uncaught exception occurs, which will receive the
32511cb0ef41Sopenharmony_ciexception value itself as its first argument.</p>
32521cb0ef41Sopenharmony_ci<p>If such a function is set, the <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event will
32531cb0ef41Sopenharmony_cinot be emitted. If <code>--abort-on-uncaught-exception</code> was passed from the
32541cb0ef41Sopenharmony_cicommand line or set through <a href="v8.html#v8setflagsfromstringflags"><code>v8.setFlagsFromString()</code></a>, the process will
32551cb0ef41Sopenharmony_cinot abort. Actions configured to take place on exceptions such as report
32561cb0ef41Sopenharmony_cigenerations will be affected too</p>
32571cb0ef41Sopenharmony_ci<p>To unset the capture function,
32581cb0ef41Sopenharmony_ci<code>process.setUncaughtExceptionCaptureCallback(null)</code> may be used. Calling this
32591cb0ef41Sopenharmony_cimethod with a non-<code>null</code> argument while another capture function is set will
32601cb0ef41Sopenharmony_cithrow an error.</p>
32611cb0ef41Sopenharmony_ci<p>Using this function is mutually exclusive with using the deprecated
32621cb0ef41Sopenharmony_ci<a href="domain.html"><code>domain</code></a> built-in module.</p>
32631cb0ef41Sopenharmony_ci</section><section><h3><code>process.sourceMapsEnabled</code><span><a class="mark" href="#processsourcemapsenabled" id="processsourcemapsenabled">#</a></span><a aria-hidden="true" class="legacy" id="process_process_sourcemapsenabled"></a></h3>
32641cb0ef41Sopenharmony_ci<div class="api_metadata">
32651cb0ef41Sopenharmony_ci<span>Added in: v18.19.0</span>
32661cb0ef41Sopenharmony_ci</div>
32671cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
32681cb0ef41Sopenharmony_ci<ul>
32691cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
32701cb0ef41Sopenharmony_ci</ul>
32711cb0ef41Sopenharmony_ci<p>The <code>process.sourceMapsEnabled</code> property returns whether the
32721cb0ef41Sopenharmony_ci<a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for stack traces is enabled.</p>
32731cb0ef41Sopenharmony_ci</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>
32741cb0ef41Sopenharmony_ci<ul>
32751cb0ef41Sopenharmony_ci<li><a href="stream.html#stream" class="type">&#x3C;Stream></a></li>
32761cb0ef41Sopenharmony_ci</ul>
32771cb0ef41Sopenharmony_ci<p>The <code>process.stderr</code> property returns a stream connected to
32781cb0ef41Sopenharmony_ci<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>
32791cb0ef41Sopenharmony_cistream) unless fd <code>2</code> refers to a file, in which case it is
32801cb0ef41Sopenharmony_cia <a href="stream.html#writable-streams">Writable</a> stream.</p>
32811cb0ef41Sopenharmony_ci<p><code>process.stderr</code> differs from other Node.js streams in important ways. See
32821cb0ef41Sopenharmony_ci<a href="#a-note-on-process-io">note on process I/O</a> for more information.</p>
32831cb0ef41Sopenharmony_ci<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>
32841cb0ef41Sopenharmony_ci<ul>
32851cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
32861cb0ef41Sopenharmony_ci</ul>
32871cb0ef41Sopenharmony_ci<p>This property refers to the value of underlying file descriptor of
32881cb0ef41Sopenharmony_ci<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,
32891cb0ef41Sopenharmony_cithis field does not exist.</p>
32901cb0ef41Sopenharmony_ci</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>
32911cb0ef41Sopenharmony_ci<ul>
32921cb0ef41Sopenharmony_ci<li><a href="stream.html#stream" class="type">&#x3C;Stream></a></li>
32931cb0ef41Sopenharmony_ci</ul>
32941cb0ef41Sopenharmony_ci<p>The <code>process.stdin</code> property returns a stream connected to
32951cb0ef41Sopenharmony_ci<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>
32961cb0ef41Sopenharmony_cistream) unless fd <code>0</code> refers to a file, in which case it is
32971cb0ef41Sopenharmony_cia <a href="stream.html#readable-streams">Readable</a> stream.</p>
32981cb0ef41Sopenharmony_ci<p>For details of how to read from <code>stdin</code> see <a href="stream.html#readablereadsize"><code>readable.read()</code></a>.</p>
32991cb0ef41Sopenharmony_ci<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
33001cb0ef41Sopenharmony_ciis compatible with scripts written for Node.js prior to v0.10.
33011cb0ef41Sopenharmony_ciFor more information see <a href="stream.html#compatibility-with-older-nodejs-versions">Stream compatibility</a>.</p>
33021cb0ef41Sopenharmony_ci<p>In "old" streams mode the <code>stdin</code> stream is paused by default, so one
33031cb0ef41Sopenharmony_cimust call <code>process.stdin.resume()</code> to read from it. Note also that calling
33041cb0ef41Sopenharmony_ci<code>process.stdin.resume()</code> itself would switch stream to "old" mode.</p>
33051cb0ef41Sopenharmony_ci<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>
33061cb0ef41Sopenharmony_ci<ul>
33071cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
33081cb0ef41Sopenharmony_ci</ul>
33091cb0ef41Sopenharmony_ci<p>This property refers to the value of underlying file descriptor of
33101cb0ef41Sopenharmony_ci<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,
33111cb0ef41Sopenharmony_cithis field does not exist.</p>
33121cb0ef41Sopenharmony_ci</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>
33131cb0ef41Sopenharmony_ci<ul>
33141cb0ef41Sopenharmony_ci<li><a href="stream.html#stream" class="type">&#x3C;Stream></a></li>
33151cb0ef41Sopenharmony_ci</ul>
33161cb0ef41Sopenharmony_ci<p>The <code>process.stdout</code> property returns a stream connected to
33171cb0ef41Sopenharmony_ci<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>
33181cb0ef41Sopenharmony_cistream) unless fd <code>1</code> refers to a file, in which case it is
33191cb0ef41Sopenharmony_cia <a href="stream.html#writable-streams">Writable</a> stream.</p>
33201cb0ef41Sopenharmony_ci<p>For example, to copy <code>process.stdin</code> to <code>process.stdout</code>:</p>
33211cb0ef41Sopenharmony_ci
33221cb0ef41Sopenharmony_ci<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>;
33231cb0ef41Sopenharmony_ci
33241cb0ef41Sopenharmony_cistdin.<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>);
33251cb0ef41Sopenharmony_ci
33261cb0ef41Sopenharmony_cistdin.<span class="hljs-title function_">pipe</span>(stdout);</code><button class="copy-button">copy</button></pre>
33271cb0ef41Sopenharmony_ci<p><code>process.stdout</code> differs from other Node.js streams in important ways. See
33281cb0ef41Sopenharmony_ci<a href="#a-note-on-process-io">note on process I/O</a> for more information.</p>
33291cb0ef41Sopenharmony_ci<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>
33301cb0ef41Sopenharmony_ci<ul>
33311cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
33321cb0ef41Sopenharmony_ci</ul>
33331cb0ef41Sopenharmony_ci<p>This property refers to the value of underlying file descriptor of
33341cb0ef41Sopenharmony_ci<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,
33351cb0ef41Sopenharmony_cithis field does not exist.</p>
33361cb0ef41Sopenharmony_ci<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>
33371cb0ef41Sopenharmony_ci<p><code>process.stdout</code> and <code>process.stderr</code> differ from other Node.js streams in
33381cb0ef41Sopenharmony_ciimportant ways:</p>
33391cb0ef41Sopenharmony_ci<ol>
33401cb0ef41Sopenharmony_ci<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>,
33411cb0ef41Sopenharmony_cirespectively.</li>
33421cb0ef41Sopenharmony_ci<li>Writes may be synchronous depending on what the stream is connected to
33431cb0ef41Sopenharmony_ciand whether the system is Windows or POSIX:
33441cb0ef41Sopenharmony_ci<ul>
33451cb0ef41Sopenharmony_ci<li>Files: <em>synchronous</em> on Windows and POSIX</li>
33461cb0ef41Sopenharmony_ci<li>TTYs (Terminals): <em>asynchronous</em> on Windows, <em>synchronous</em> on POSIX</li>
33471cb0ef41Sopenharmony_ci<li>Pipes (and sockets): <em>synchronous</em> on Windows, <em>asynchronous</em> on POSIX</li>
33481cb0ef41Sopenharmony_ci</ul>
33491cb0ef41Sopenharmony_ci</li>
33501cb0ef41Sopenharmony_ci</ol>
33511cb0ef41Sopenharmony_ci<p>These behaviors are partly for historical reasons, as changing them would
33521cb0ef41Sopenharmony_cicreate backward incompatibility, but they are also expected by some users.</p>
33531cb0ef41Sopenharmony_ci<p>Synchronous writes avoid problems such as output written with <code>console.log()</code> or
33541cb0ef41Sopenharmony_ci<code>console.error()</code> being unexpectedly interleaved, or not written at all if
33551cb0ef41Sopenharmony_ci<code>process.exit()</code> is called before an asynchronous write completes. See
33561cb0ef41Sopenharmony_ci<a href="#processexitcode"><code>process.exit()</code></a> for more information.</p>
33571cb0ef41Sopenharmony_ci<p><em><strong>Warning</strong></em>: Synchronous writes block the event loop until the write has
33581cb0ef41Sopenharmony_cicompleted. This can be near instantaneous in the case of output to a file, but
33591cb0ef41Sopenharmony_ciunder high system load, pipes that are not being read at the receiving end, or
33601cb0ef41Sopenharmony_ciwith slow terminals or file systems, it's possible for the event loop to be
33611cb0ef41Sopenharmony_ciblocked often enough and long enough to have severe negative performance
33621cb0ef41Sopenharmony_ciimpacts. This may not be a problem when writing to an interactive terminal
33631cb0ef41Sopenharmony_cisession, but consider this particularly careful when doing production logging to
33641cb0ef41Sopenharmony_cithe process output streams.</p>
33651cb0ef41Sopenharmony_ci<p>To check if a stream is connected to a <a href="tty.html#tty">TTY</a> context, check the <code>isTTY</code>
33661cb0ef41Sopenharmony_ciproperty.</p>
33671cb0ef41Sopenharmony_ci<p>For instance:</p>
33681cb0ef41Sopenharmony_ci<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>
33691cb0ef41Sopenharmony_citrue
33701cb0ef41Sopenharmony_ci<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>
33711cb0ef41Sopenharmony_cifalse
33721cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span></span>
33731cb0ef41Sopenharmony_citrue
33741cb0ef41Sopenharmony_ci<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>
33751cb0ef41Sopenharmony_cifalse</code> <button class="copy-button">copy</button></pre>
33761cb0ef41Sopenharmony_ci<p>See the <a href="tty.html#tty">TTY</a> documentation for more information.</p>
33771cb0ef41Sopenharmony_ci</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>
33781cb0ef41Sopenharmony_ci<div class="api_metadata">
33791cb0ef41Sopenharmony_ci<span>Added in: v0.9.12</span>
33801cb0ef41Sopenharmony_ci</div>
33811cb0ef41Sopenharmony_ci<ul>
33821cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
33831cb0ef41Sopenharmony_ci</ul>
33841cb0ef41Sopenharmony_ci<p>The initial value of <code>process.throwDeprecation</code> indicates whether the
33851cb0ef41Sopenharmony_ci<code>--throw-deprecation</code> flag is set on the current Node.js process.
33861cb0ef41Sopenharmony_ci<code>process.throwDeprecation</code> is mutable, so whether or not deprecation
33871cb0ef41Sopenharmony_ciwarnings result in errors may be altered at runtime. See the
33881cb0ef41Sopenharmony_cidocumentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the
33891cb0ef41Sopenharmony_ci<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information.</p>
33901cb0ef41Sopenharmony_ci<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>
33911cb0ef41Sopenharmony_citrue
33921cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"process.throwDeprecation"</span></span>
33931cb0ef41Sopenharmony_ciundefined
33941cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span>
33951cb0ef41Sopenharmony_ci<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>
33961cb0ef41Sopenharmony_ciundefined
33971cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">(node:26598) DeprecationWarning: <span class="hljs-built_in">test</span></span>
33981cb0ef41Sopenharmony_ci<span class="hljs-meta prompt_">> </span><span class="language-bash">process.throwDeprecation = <span class="hljs-literal">true</span>;</span>
33991cb0ef41Sopenharmony_citrue
34001cb0ef41Sopenharmony_ci<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>
34011cb0ef41Sopenharmony_ciThrown:
34021cb0ef41Sopenharmony_ci[DeprecationWarning: test] { name: 'DeprecationWarning' }</code> <button class="copy-button">copy</button></pre>
34031cb0ef41Sopenharmony_ci</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>
34041cb0ef41Sopenharmony_ci<div class="api_metadata">
34051cb0ef41Sopenharmony_ci<span>Added in: v0.1.104</span>
34061cb0ef41Sopenharmony_ci</div>
34071cb0ef41Sopenharmony_ci<ul>
34081cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
34091cb0ef41Sopenharmony_ci</ul>
34101cb0ef41Sopenharmony_ci<p>The <code>process.title</code> property returns the current process title (i.e. returns
34111cb0ef41Sopenharmony_cithe current value of <code>ps</code>). Assigning a new value to <code>process.title</code> modifies
34121cb0ef41Sopenharmony_cithe current value of <code>ps</code>.</p>
34131cb0ef41Sopenharmony_ci<p>When a new value is assigned, different platforms will impose different maximum
34141cb0ef41Sopenharmony_cilength restrictions on the title. Usually such restrictions are quite limited.
34151cb0ef41Sopenharmony_ciFor instance, on Linux and macOS, <code>process.title</code> is limited to the size of the
34161cb0ef41Sopenharmony_cibinary name plus the length of the command-line arguments because setting the
34171cb0ef41Sopenharmony_ci<code>process.title</code> overwrites the <code>argv</code> memory of the process. Node.js v0.8
34181cb0ef41Sopenharmony_ciallowed for longer process title strings by also overwriting the <code>environ</code>
34191cb0ef41Sopenharmony_cimemory but that was potentially insecure and confusing in some (rather obscure)
34201cb0ef41Sopenharmony_cicases.</p>
34211cb0ef41Sopenharmony_ci<p>Assigning a value to <code>process.title</code> might not result in an accurate label
34221cb0ef41Sopenharmony_ciwithin process manager applications such as macOS Activity Monitor or Windows
34231cb0ef41Sopenharmony_ciServices Manager.</p>
34241cb0ef41Sopenharmony_ci</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>
34251cb0ef41Sopenharmony_ci<div class="api_metadata">
34261cb0ef41Sopenharmony_ci<span>Added in: v0.8.0</span>
34271cb0ef41Sopenharmony_ci</div>
34281cb0ef41Sopenharmony_ci<ul>
34291cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
34301cb0ef41Sopenharmony_ci</ul>
34311cb0ef41Sopenharmony_ci<p>The <code>process.traceDeprecation</code> property indicates whether the
34321cb0ef41Sopenharmony_ci<code>--trace-deprecation</code> flag is set on the current Node.js process. See the
34331cb0ef41Sopenharmony_cidocumentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the
34341cb0ef41Sopenharmony_ci<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this
34351cb0ef41Sopenharmony_ciflag's behavior.</p>
34361cb0ef41Sopenharmony_ci</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>
34371cb0ef41Sopenharmony_ci<div class="api_metadata">
34381cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
34391cb0ef41Sopenharmony_ci<table>
34401cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
34411cb0ef41Sopenharmony_ci<tr><td>v14.0.0, v12.19.0</td>
34421cb0ef41Sopenharmony_ci<td><p>Calling <code>process.umask()</code> with no arguments is deprecated.</p></td></tr>
34431cb0ef41Sopenharmony_ci<tr><td>v0.1.19</td>
34441cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.1.19</span></p></td></tr>
34451cb0ef41Sopenharmony_ci</tbody></table>
34461cb0ef41Sopenharmony_ci</details>
34471cb0ef41Sopenharmony_ci</div>
34481cb0ef41Sopenharmony_ci<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
34491cb0ef41Sopenharmony_cithe process-wide umask to be written twice. This introduces a race condition
34501cb0ef41Sopenharmony_cibetween threads, and is a potential security vulnerability. There is no safe,
34511cb0ef41Sopenharmony_cicross-platform alternative API.</div><p></p>
34521cb0ef41Sopenharmony_ci<p><code>process.umask()</code> returns the Node.js process's file mode creation mask. Child
34531cb0ef41Sopenharmony_ciprocesses inherit the mask from the parent process.</p>
34541cb0ef41Sopenharmony_ci</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>
34551cb0ef41Sopenharmony_ci<div class="api_metadata">
34561cb0ef41Sopenharmony_ci<span>Added in: v0.1.19</span>
34571cb0ef41Sopenharmony_ci</div>
34581cb0ef41Sopenharmony_ci<ul>
34591cb0ef41Sopenharmony_ci<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>
34601cb0ef41Sopenharmony_ci</ul>
34611cb0ef41Sopenharmony_ci<p><code>process.umask(mask)</code> sets the Node.js process's file mode creation mask. Child
34621cb0ef41Sopenharmony_ciprocesses inherit the mask from the parent process. Returns the previous mask.</p>
34631cb0ef41Sopenharmony_ci
34641cb0ef41Sopenharmony_ci<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>;
34651cb0ef41Sopenharmony_ci
34661cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>;
34671cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask);
34681cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(
34691cb0ef41Sopenharmony_ci  <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>,
34701cb0ef41Sopenharmony_ci);</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>);
34711cb0ef41Sopenharmony_ci
34721cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>;
34731cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask);
34741cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(
34751cb0ef41Sopenharmony_ci  <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>,
34761cb0ef41Sopenharmony_ci);</code><button class="copy-button">copy</button></pre>
34771cb0ef41Sopenharmony_ci<p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, <code>process.umask(mask)</code> will throw an exception.</p>
34781cb0ef41Sopenharmony_ci</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>
34791cb0ef41Sopenharmony_ci<div class="api_metadata">
34801cb0ef41Sopenharmony_ci<span>Added in: v0.5.0</span>
34811cb0ef41Sopenharmony_ci</div>
34821cb0ef41Sopenharmony_ci<ul>
34831cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
34841cb0ef41Sopenharmony_ci</ul>
34851cb0ef41Sopenharmony_ci<p>The <code>process.uptime()</code> method returns the number of seconds the current Node.js
34861cb0ef41Sopenharmony_ciprocess has been running.</p>
34871cb0ef41Sopenharmony_ci<p>The return value includes fractions of a second. Use <code>Math.floor()</code> to get whole
34881cb0ef41Sopenharmony_ciseconds.</p>
34891cb0ef41Sopenharmony_ci</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>
34901cb0ef41Sopenharmony_ci<div class="api_metadata">
34911cb0ef41Sopenharmony_ci<span>Added in: v0.1.3</span>
34921cb0ef41Sopenharmony_ci</div>
34931cb0ef41Sopenharmony_ci<ul>
34941cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
34951cb0ef41Sopenharmony_ci</ul>
34961cb0ef41Sopenharmony_ci<p>The <code>process.version</code> property contains the Node.js version string.</p>
34971cb0ef41Sopenharmony_ci
34981cb0ef41Sopenharmony_ci<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>;
34991cb0ef41Sopenharmony_ci
35001cb0ef41Sopenharmony_ci<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>);
35011cb0ef41Sopenharmony_ci<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>);
35021cb0ef41Sopenharmony_ci
35031cb0ef41Sopenharmony_ci<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>);
35041cb0ef41Sopenharmony_ci<span class="hljs-comment">// Version: v14.8.0</span></code><button class="copy-button">copy</button></pre>
35051cb0ef41Sopenharmony_ci<p>To get the version string without the prepended <em>v</em>, use
35061cb0ef41Sopenharmony_ci<code>process.versions.node</code>.</p>
35071cb0ef41Sopenharmony_ci</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>
35081cb0ef41Sopenharmony_ci<div class="api_metadata">
35091cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
35101cb0ef41Sopenharmony_ci<table>
35111cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
35121cb0ef41Sopenharmony_ci<tr><td>v9.0.0</td>
35131cb0ef41Sopenharmony_ci<td><p>The <code>v8</code> property now includes a Node.js specific suffix.</p></td></tr>
35141cb0ef41Sopenharmony_ci<tr><td>v4.2.0</td>
35151cb0ef41Sopenharmony_ci<td><p>The <code>icu</code> property is now supported.</p></td></tr>
35161cb0ef41Sopenharmony_ci<tr><td>v0.2.0</td>
35171cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.2.0</span></p></td></tr>
35181cb0ef41Sopenharmony_ci</tbody></table>
35191cb0ef41Sopenharmony_ci</details>
35201cb0ef41Sopenharmony_ci</div>
35211cb0ef41Sopenharmony_ci<ul>
35221cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
35231cb0ef41Sopenharmony_ci</ul>
35241cb0ef41Sopenharmony_ci<p>The <code>process.versions</code> property returns an object listing the version strings of
35251cb0ef41Sopenharmony_ciNode.js and its dependencies. <code>process.versions.modules</code> indicates the current
35261cb0ef41Sopenharmony_ciABI version, which is increased whenever a C++ API changes. Node.js will refuse
35271cb0ef41Sopenharmony_cito load modules that were compiled against a different module ABI version.</p>
35281cb0ef41Sopenharmony_ci
35291cb0ef41Sopenharmony_ci<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>;
35301cb0ef41Sopenharmony_ci
35311cb0ef41Sopenharmony_ci<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>);
35321cb0ef41Sopenharmony_ci
35331cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(versions);</code><button class="copy-button">copy</button></pre>
35341cb0ef41Sopenharmony_ci<p>Will generate an object similar to:</p>
35351cb0ef41Sopenharmony_ci<pre><code class="language-console">{ node: '11.13.0',
35361cb0ef41Sopenharmony_ci  v8: '7.0.276.38-node.18',
35371cb0ef41Sopenharmony_ci  uv: '1.27.0',
35381cb0ef41Sopenharmony_ci  zlib: '1.2.11',
35391cb0ef41Sopenharmony_ci  brotli: '1.0.7',
35401cb0ef41Sopenharmony_ci  ares: '1.15.0',
35411cb0ef41Sopenharmony_ci  modules: '67',
35421cb0ef41Sopenharmony_ci  nghttp2: '1.34.0',
35431cb0ef41Sopenharmony_ci  napi: '4',
35441cb0ef41Sopenharmony_ci  llhttp: '1.1.1',
35451cb0ef41Sopenharmony_ci  openssl: '1.1.1b',
35461cb0ef41Sopenharmony_ci  cldr: '34.0',
35471cb0ef41Sopenharmony_ci  icu: '63.1',
35481cb0ef41Sopenharmony_ci  tz: '2018e',
35491cb0ef41Sopenharmony_ci  unicode: '11.0' }</code> <button class="copy-button">copy</button></pre>
35501cb0ef41Sopenharmony_ci</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>
35511cb0ef41Sopenharmony_ci<p>Node.js will normally exit with a <code>0</code> status code when no more async
35521cb0ef41Sopenharmony_cioperations are pending. The following status codes are used in other
35531cb0ef41Sopenharmony_cicases:</p>
35541cb0ef41Sopenharmony_ci<ul>
35551cb0ef41Sopenharmony_ci<li><code>1</code> <strong>Uncaught Fatal Exception</strong>: There was an uncaught exception,
35561cb0ef41Sopenharmony_ciand it was not handled by a domain or an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event
35571cb0ef41Sopenharmony_cihandler.</li>
35581cb0ef41Sopenharmony_ci<li><code>2</code>: Unused (reserved by Bash for builtin misuse)</li>
35591cb0ef41Sopenharmony_ci<li><code>3</code> <strong>Internal JavaScript Parse Error</strong>: The JavaScript source code
35601cb0ef41Sopenharmony_ciinternal in the Node.js bootstrapping process caused a parse error. This
35611cb0ef41Sopenharmony_ciis extremely rare, and generally can only happen during development
35621cb0ef41Sopenharmony_ciof Node.js itself.</li>
35631cb0ef41Sopenharmony_ci<li><code>4</code> <strong>Internal JavaScript Evaluation Failure</strong>: The JavaScript
35641cb0ef41Sopenharmony_cisource code internal in the Node.js bootstrapping process failed to
35651cb0ef41Sopenharmony_cireturn a function value when evaluated. This is extremely rare, and
35661cb0ef41Sopenharmony_cigenerally can only happen during development of Node.js itself.</li>
35671cb0ef41Sopenharmony_ci<li><code>5</code> <strong>Fatal Error</strong>: There was a fatal unrecoverable error in V8.
35681cb0ef41Sopenharmony_ciTypically a message will be printed to stderr with the prefix <code>FATAL ERROR</code>.</li>
35691cb0ef41Sopenharmony_ci<li><code>6</code> <strong>Non-function Internal Exception Handler</strong>: There was an
35701cb0ef41Sopenharmony_ciuncaught exception, but the internal fatal exception handler
35711cb0ef41Sopenharmony_cifunction was somehow set to a non-function, and could not be called.</li>
35721cb0ef41Sopenharmony_ci<li><code>7</code> <strong>Internal Exception Handler Run-Time Failure</strong>: There was an
35731cb0ef41Sopenharmony_ciuncaught exception, and the internal fatal exception handler
35741cb0ef41Sopenharmony_cifunction itself threw an error while attempting to handle it. This
35751cb0ef41Sopenharmony_cican happen, for example, if an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> or
35761cb0ef41Sopenharmony_ci<code>domain.on('error')</code> handler throws an error.</li>
35771cb0ef41Sopenharmony_ci<li><code>8</code>: Unused. In previous versions of Node.js, exit code 8 sometimes
35781cb0ef41Sopenharmony_ciindicated an uncaught exception.</li>
35791cb0ef41Sopenharmony_ci<li><code>9</code> <strong>Invalid Argument</strong>: Either an unknown option was specified,
35801cb0ef41Sopenharmony_cior an option requiring a value was provided without a value.</li>
35811cb0ef41Sopenharmony_ci<li><code>10</code> <strong>Internal JavaScript Run-Time Failure</strong>: The JavaScript
35821cb0ef41Sopenharmony_cisource code internal in the Node.js bootstrapping process threw an error
35831cb0ef41Sopenharmony_ciwhen the bootstrapping function was called. This is extremely rare,
35841cb0ef41Sopenharmony_ciand generally can only happen during development of Node.js itself.</li>
35851cb0ef41Sopenharmony_ci<li><code>12</code> <strong>Invalid Debug Argument</strong>: The <code>--inspect</code> and/or <code>--inspect-brk</code>
35861cb0ef41Sopenharmony_cioptions were set, but the port number chosen was invalid or unavailable.</li>
35871cb0ef41Sopenharmony_ci<li><code>13</code> <strong>Unfinished Top-Level Await</strong>: <code>await</code> was used outside of a function
35881cb0ef41Sopenharmony_ciin the top-level code, but the passed <code>Promise</code> never resolved.</li>
35891cb0ef41Sopenharmony_ci<li><code>14</code> <strong>Snapshot Failure</strong>: Node.js was started to build a V8 startup
35901cb0ef41Sopenharmony_cisnapshot and it failed because certain requirements of the state of
35911cb0ef41Sopenharmony_cithe application were not met.</li>
35921cb0ef41Sopenharmony_ci<li><code>>128</code> <strong>Signal Exits</strong>: If Node.js receives a fatal signal such as
35931cb0ef41Sopenharmony_ci<code>SIGKILL</code> or <code>SIGHUP</code>, then its exit code will be <code>128</code> plus the
35941cb0ef41Sopenharmony_civalue of the signal code. This is a standard POSIX practice, since
35951cb0ef41Sopenharmony_ciexit codes are defined to be 7-bit integers, and signal exits set
35961cb0ef41Sopenharmony_cithe high-order bit, and then contain the value of the signal code.
35971cb0ef41Sopenharmony_ciFor example, signal <code>SIGABRT</code> has value <code>6</code>, so the expected exit
35981cb0ef41Sopenharmony_cicode will be <code>128</code> + <code>6</code>, or <code>134</code>.</li>
35991cb0ef41Sopenharmony_ci</ul></section>
36001cb0ef41Sopenharmony_ci        <!-- API END -->
36011cb0ef41Sopenharmony_ci      </div>
36021cb0ef41Sopenharmony_ci    </div>
36031cb0ef41Sopenharmony_ci  </div>
36041cb0ef41Sopenharmony_ci</body>
36051cb0ef41Sopenharmony_ci</html>
3606