Server IP : 85.214.239.14 / Your IP : 3.147.46.174 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/task/2/cwd/proc/3/cwd/usr/share/doc/nodejs/api/ |
Upload File : |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <meta name="nodejs.org:node-version" content="v20.18.0"> <title>Process | Node.js v20.18.0 Documentation</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback"> <link rel="stylesheet" href="assets/style.css"> <link rel="stylesheet" href="assets/hljs.css"> <link rel="canonical" href="https://nodejs.org/api/process.html"> <script async defer src="assets/api.js" type="text/javascript"></script> <script> const storedTheme = localStorage.getItem('theme'); // Follow operating system theme preference if (storedTheme === null && window.matchMedia) { const mq = window.matchMedia('(prefers-color-scheme: dark)'); if (mq.matches) { document.documentElement.classList.add('dark-mode'); } } else if (storedTheme === 'dark') { document.documentElement.classList.add('dark-mode'); } </script> <style>@media(max-width:542px){.with-40-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:734px){.with-64-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:550px){.with-41-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:598px){.with-47-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:582px){.with-45-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:566px){.with-43-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:606px){.with-48-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:694px){.with-59-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:750px){.with-66-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:622px){.with-50-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:558px){.with-42-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:574px){.with-44-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}</style> </head> <body class="alt apidoc" id="api-section-process"> <div id="content" class="clearfix"> <div role="navigation" id="column2" class="interior"> <div id="intro" class="interior"> <a href="/" title="Go back to the home page"> Node.js </a> </div> <ul> <li><a href="documentation.html" class="nav-documentation">About this documentation</a></li> <li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li> </ul> <hr class="line"> <ul> <li><a href="assert.html" class="nav-assert">Assertion testing</a></li> <li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li> <li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li> <li><a href="buffer.html" class="nav-buffer">Buffer</a></li> <li><a href="addons.html" class="nav-addons">C++ addons</a></li> <li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li> <li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li> <li><a href="child_process.html" class="nav-child_process">Child processes</a></li> <li><a href="cluster.html" class="nav-cluster">Cluster</a></li> <li><a href="cli.html" class="nav-cli">Command-line options</a></li> <li><a href="console.html" class="nav-console">Console</a></li> <li><a href="corepack.html" class="nav-corepack">Corepack</a></li> <li><a href="crypto.html" class="nav-crypto">Crypto</a></li> <li><a href="debugger.html" class="nav-debugger">Debugger</a></li> <li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li> <li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li> <li><a href="dns.html" class="nav-dns">DNS</a></li> <li><a href="domain.html" class="nav-domain">Domain</a></li> <li><a href="errors.html" class="nav-errors">Errors</a></li> <li><a href="events.html" class="nav-events">Events</a></li> <li><a href="fs.html" class="nav-fs">File system</a></li> <li><a href="globals.html" class="nav-globals">Globals</a></li> <li><a href="http.html" class="nav-http">HTTP</a></li> <li><a href="http2.html" class="nav-http2">HTTP/2</a></li> <li><a href="https.html" class="nav-https">HTTPS</a></li> <li><a href="inspector.html" class="nav-inspector">Inspector</a></li> <li><a href="intl.html" class="nav-intl">Internationalization</a></li> <li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li> <li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li> <li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li> <li><a href="packages.html" class="nav-packages">Modules: Packages</a></li> <li><a href="net.html" class="nav-net">Net</a></li> <li><a href="os.html" class="nav-os">OS</a></li> <li><a href="path.html" class="nav-path">Path</a></li> <li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li> <li><a href="permissions.html" class="nav-permissions">Permissions</a></li> <li><a href="process.html" class="nav-process active">Process</a></li> <li><a href="punycode.html" class="nav-punycode">Punycode</a></li> <li><a href="querystring.html" class="nav-querystring">Query strings</a></li> <li><a href="readline.html" class="nav-readline">Readline</a></li> <li><a href="repl.html" class="nav-repl">REPL</a></li> <li><a href="report.html" class="nav-report">Report</a></li> <li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li> <li><a href="stream.html" class="nav-stream">Stream</a></li> <li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li> <li><a href="test.html" class="nav-test">Test runner</a></li> <li><a href="timers.html" class="nav-timers">Timers</a></li> <li><a href="tls.html" class="nav-tls">TLS/SSL</a></li> <li><a href="tracing.html" class="nav-tracing">Trace events</a></li> <li><a href="tty.html" class="nav-tty">TTY</a></li> <li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li> <li><a href="url.html" class="nav-url">URL</a></li> <li><a href="util.html" class="nav-util">Utilities</a></li> <li><a href="v8.html" class="nav-v8">V8</a></li> <li><a href="vm.html" class="nav-vm">VM</a></li> <li><a href="wasi.html" class="nav-wasi">WASI</a></li> <li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li> <li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li> <li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li> <li><a href="zlib.html" class="nav-zlib">Zlib</a></li> </ul> <hr class="line"> <ul> <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li> </ul> </div> <div id="column1" data-id="process" class="interior"> <header class="header"> <div class="header-container"> <h1>Node.js v20.18.0 documentation</h1> <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden> <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24"> <path fill="none" d="M0 0h24v24H0z" /> <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"/> <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"/> </svg> <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24"> <path d="M0 0h24v24H0z" fill="none" /> <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"/> </svg> </button> </div> <div id="gtoc"> <ul> <li class="pinned-header">Node.js v20.18.0</li> <li class="picker-header"> <a href="#"> <span class="picker-arrow"></span> Table of contents </a> <div class="picker"><div class="toc"><ul> <li><a href="#process">Process</a> <ul> <li><a href="#process-events">Process events</a> <ul> <li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li> <li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li> <li><a href="#event-exit">Event: <code>'exit'</code></a></li> <li><a href="#event-message">Event: <code>'message'</code></a></li> <li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li> <li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li> <li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a> <ul> <li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li> </ul> </li> <li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li> <li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li> <li><a href="#event-warning">Event: <code>'warning'</code></a> <ul> <li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li> <li><a href="#nodejs-warning-names">Node.js warning names</a></li> </ul> </li> <li><a href="#event-worker">Event: <code>'worker'</code></a></li> <li><a href="#signal-events">Signal events</a></li> </ul> </li> <li><a href="#processabort"><code>process.abort()</code></a></li> <li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li> <li><a href="#processarch"><code>process.arch</code></a></li> <li><a href="#processargv"><code>process.argv</code></a></li> <li><a href="#processargv0"><code>process.argv0</code></a></li> <li><a href="#processchannel"><code>process.channel</code></a> <ul> <li><a href="#processchannelref"><code>process.channel.ref()</code></a></li> <li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li> </ul> </li> <li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li> <li><a href="#processconfig"><code>process.config</code></a></li> <li><a href="#processconnected"><code>process.connected</code></a></li> <li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li> <li><span class="stability_1"><a href="#processavailablememory"><code>process.availableMemory()</code></a></span></li> <li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li> <li><a href="#processcwd"><code>process.cwd()</code></a></li> <li><a href="#processdebugport"><code>process.debugPort</code></a></li> <li><a href="#processdisconnect"><code>process.disconnect()</code></a></li> <li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li> <li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li> <li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a> <ul> <li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li> </ul> </li> <li><a href="#processenv"><code>process.env</code></a></li> <li><a href="#processexecargv"><code>process.execArgv</code></a></li> <li><a href="#processexecpath"><code>process.execPath</code></a></li> <li><a href="#processexitcode"><code>process.exit([code])</code></a></li> <li><a href="#processexitcode_1"><code>process.exitCode</code></a></li> <li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li> <li><a href="#processgetbuiltinmoduleid"><code>process.getBuiltinModule(id)</code></a></li> <li><a href="#processgetegid"><code>process.getegid()</code></a></li> <li><a href="#processgeteuid"><code>process.geteuid()</code></a></li> <li><a href="#processgetgid"><code>process.getgid()</code></a></li> <li><a href="#processgetgroups"><code>process.getgroups()</code></a></li> <li><a href="#processgetuid"><code>process.getuid()</code></a></li> <li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li> <li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li> <li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li> <li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li> <li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li> <li><span class="stability_1"><a href="#processloadenvfilepath"><code>process.loadEnvFile(path)</code></a></span></li> <li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li> <li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li> <li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li> <li><span class="stability_3"><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a></span> <ul> <li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li> </ul> </li> <li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li> <li><a href="#processpermission"><code>process.permission</code></a> <ul> <li><a href="#processpermissionhasscope-reference"><code>process.permission.has(scope[, reference])</code></a></li> </ul> </li> <li><a href="#processpid"><code>process.pid</code></a></li> <li><a href="#processplatform"><code>process.platform</code></a></li> <li><a href="#processppid"><code>process.ppid</code></a></li> <li><a href="#processrelease"><code>process.release</code></a></li> <li><a href="#processreport"><code>process.report</code></a> <ul> <li><a href="#processreportcompact"><code>process.report.compact</code></a></li> <li><a href="#processreportdirectory"><code>process.report.directory</code></a></li> <li><a href="#processreportfilename"><code>process.report.filename</code></a></li> <li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li> <li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li> <li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li> <li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li> <li><a href="#processreportsignal"><code>process.report.signal</code></a></li> <li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li> </ul> </li> <li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li> <li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li> <li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li> <li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li> <li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li> <li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li> <li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li> <li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li> <li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li> <li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li> <li><a href="#processstderr"><code>process.stderr</code></a> <ul> <li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li> </ul> </li> <li><a href="#processstdin"><code>process.stdin</code></a> <ul> <li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li> </ul> </li> <li><a href="#processstdout"><code>process.stdout</code></a> <ul> <li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li> <li><a href="#a-note-on-process-io">A note on process I/O</a></li> </ul> </li> <li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li> <li><a href="#processtitle"><code>process.title</code></a></li> <li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li> <li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li> <li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li> <li><a href="#processuptime"><code>process.uptime()</code></a></li> <li><a href="#processversion"><code>process.version</code></a></li> <li><a href="#processversions"><code>process.versions</code></a></li> <li><a href="#exit-codes">Exit codes</a></li> </ul> </li> </ul></div></div> </li> <li class="picker-header"> <a href="#"> <span class="picker-arrow"></span> Index </a> <div class="picker"><ul> <li><a href="documentation.html" class="nav-documentation">About this documentation</a></li> <li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li> <li> <a href="index.html">Index</a> </li> </ul> <hr class="line"> <ul> <li><a href="assert.html" class="nav-assert">Assertion testing</a></li> <li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li> <li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li> <li><a href="buffer.html" class="nav-buffer">Buffer</a></li> <li><a href="addons.html" class="nav-addons">C++ addons</a></li> <li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li> <li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li> <li><a href="child_process.html" class="nav-child_process">Child processes</a></li> <li><a href="cluster.html" class="nav-cluster">Cluster</a></li> <li><a href="cli.html" class="nav-cli">Command-line options</a></li> <li><a href="console.html" class="nav-console">Console</a></li> <li><a href="corepack.html" class="nav-corepack">Corepack</a></li> <li><a href="crypto.html" class="nav-crypto">Crypto</a></li> <li><a href="debugger.html" class="nav-debugger">Debugger</a></li> <li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li> <li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li> <li><a href="dns.html" class="nav-dns">DNS</a></li> <li><a href="domain.html" class="nav-domain">Domain</a></li> <li><a href="errors.html" class="nav-errors">Errors</a></li> <li><a href="events.html" class="nav-events">Events</a></li> <li><a href="fs.html" class="nav-fs">File system</a></li> <li><a href="globals.html" class="nav-globals">Globals</a></li> <li><a href="http.html" class="nav-http">HTTP</a></li> <li><a href="http2.html" class="nav-http2">HTTP/2</a></li> <li><a href="https.html" class="nav-https">HTTPS</a></li> <li><a href="inspector.html" class="nav-inspector">Inspector</a></li> <li><a href="intl.html" class="nav-intl">Internationalization</a></li> <li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li> <li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li> <li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li> <li><a href="packages.html" class="nav-packages">Modules: Packages</a></li> <li><a href="net.html" class="nav-net">Net</a></li> <li><a href="os.html" class="nav-os">OS</a></li> <li><a href="path.html" class="nav-path">Path</a></li> <li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li> <li><a href="permissions.html" class="nav-permissions">Permissions</a></li> <li><a href="process.html" class="nav-process active">Process</a></li> <li><a href="punycode.html" class="nav-punycode">Punycode</a></li> <li><a href="querystring.html" class="nav-querystring">Query strings</a></li> <li><a href="readline.html" class="nav-readline">Readline</a></li> <li><a href="repl.html" class="nav-repl">REPL</a></li> <li><a href="report.html" class="nav-report">Report</a></li> <li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li> <li><a href="stream.html" class="nav-stream">Stream</a></li> <li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li> <li><a href="test.html" class="nav-test">Test runner</a></li> <li><a href="timers.html" class="nav-timers">Timers</a></li> <li><a href="tls.html" class="nav-tls">TLS/SSL</a></li> <li><a href="tracing.html" class="nav-tracing">Trace events</a></li> <li><a href="tty.html" class="nav-tty">TTY</a></li> <li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li> <li><a href="url.html" class="nav-url">URL</a></li> <li><a href="util.html" class="nav-util">Utilities</a></li> <li><a href="v8.html" class="nav-v8">V8</a></li> <li><a href="vm.html" class="nav-vm">VM</a></li> <li><a href="wasi.html" class="nav-wasi">WASI</a></li> <li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li> <li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li> <li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li> <li><a href="zlib.html" class="nav-zlib">Zlib</a></li> </ul> <hr class="line"> <ul> <li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li> </ul></div> </li> <li class="picker-header"> <a href="#"> <span class="picker-arrow"></span> Other versions </a> <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v22.x/api/process.html">22.x</a></li> <li><a href="https://nodejs.org/docs/latest-v21.x/api/process.html">21.x</a></li> <li><a href="https://nodejs.org/docs/latest-v20.x/api/process.html">20.x <b>LTS</b></a></li> <li><a href="https://nodejs.org/docs/latest-v19.x/api/process.html">19.x</a></li> <li><a href="https://nodejs.org/docs/latest-v18.x/api/process.html">18.x <b>LTS</b></a></li> <li><a href="https://nodejs.org/docs/latest-v17.x/api/process.html">17.x</a></li> <li><a href="https://nodejs.org/docs/latest-v16.x/api/process.html">16.x</a></li> <li><a href="https://nodejs.org/docs/latest-v15.x/api/process.html">15.x</a></li> <li><a href="https://nodejs.org/docs/latest-v14.x/api/process.html">14.x</a></li> <li><a href="https://nodejs.org/docs/latest-v13.x/api/process.html">13.x</a></li> <li><a href="https://nodejs.org/docs/latest-v12.x/api/process.html">12.x</a></li> <li><a href="https://nodejs.org/docs/latest-v11.x/api/process.html">11.x</a></li> <li><a href="https://nodejs.org/docs/latest-v10.x/api/process.html">10.x</a></li> <li><a href="https://nodejs.org/docs/latest-v9.x/api/process.html">9.x</a></li> <li><a href="https://nodejs.org/docs/latest-v8.x/api/process.html">8.x</a></li> <li><a href="https://nodejs.org/docs/latest-v7.x/api/process.html">7.x</a></li> <li><a href="https://nodejs.org/docs/latest-v6.x/api/process.html">6.x</a></li> <li><a href="https://nodejs.org/docs/latest-v5.x/api/process.html">5.x</a></li> <li><a href="https://nodejs.org/docs/latest-v4.x/api/process.html">4.x</a></li> <li><a href="https://nodejs.org/docs/latest-v0.12.x/api/process.html">0.12.x</a></li> <li><a href="https://nodejs.org/docs/latest-v0.10.x/api/process.html">0.10.x</a></li></ol></div> </li> <li class="picker-header"> <a href="#"> <span class="picker-arrow"></span> Options </a> <div class="picker"> <ul> <li> <a href="all.html">View on single page</a> </li> <li> <a href="process.json">View as JSON</a> </li> <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/process.md">Edit on GitHub</a></li> </ul> </div> </li> </ul> </div> <hr> </header> <details role="navigation" id="toc" open><summary>Table of contents</summary><ul> <li><a href="#process">Process</a> <ul> <li><a href="#process-events">Process events</a> <ul> <li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li> <li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li> <li><a href="#event-exit">Event: <code>'exit'</code></a></li> <li><a href="#event-message">Event: <code>'message'</code></a></li> <li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li> <li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li> <li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a> <ul> <li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li> </ul> </li> <li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li> <li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li> <li><a href="#event-warning">Event: <code>'warning'</code></a> <ul> <li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li> <li><a href="#nodejs-warning-names">Node.js warning names</a></li> </ul> </li> <li><a href="#event-worker">Event: <code>'worker'</code></a></li> <li><a href="#signal-events">Signal events</a></li> </ul> </li> <li><a href="#processabort"><code>process.abort()</code></a></li> <li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li> <li><a href="#processarch"><code>process.arch</code></a></li> <li><a href="#processargv"><code>process.argv</code></a></li> <li><a href="#processargv0"><code>process.argv0</code></a></li> <li><a href="#processchannel"><code>process.channel</code></a> <ul> <li><a href="#processchannelref"><code>process.channel.ref()</code></a></li> <li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li> </ul> </li> <li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li> <li><a href="#processconfig"><code>process.config</code></a></li> <li><a href="#processconnected"><code>process.connected</code></a></li> <li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li> <li><span class="stability_1"><a href="#processavailablememory"><code>process.availableMemory()</code></a></span></li> <li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li> <li><a href="#processcwd"><code>process.cwd()</code></a></li> <li><a href="#processdebugport"><code>process.debugPort</code></a></li> <li><a href="#processdisconnect"><code>process.disconnect()</code></a></li> <li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li> <li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li> <li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a> <ul> <li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li> </ul> </li> <li><a href="#processenv"><code>process.env</code></a></li> <li><a href="#processexecargv"><code>process.execArgv</code></a></li> <li><a href="#processexecpath"><code>process.execPath</code></a></li> <li><a href="#processexitcode"><code>process.exit([code])</code></a></li> <li><a href="#processexitcode_1"><code>process.exitCode</code></a></li> <li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li> <li><a href="#processgetbuiltinmoduleid"><code>process.getBuiltinModule(id)</code></a></li> <li><a href="#processgetegid"><code>process.getegid()</code></a></li> <li><a href="#processgeteuid"><code>process.geteuid()</code></a></li> <li><a href="#processgetgid"><code>process.getgid()</code></a></li> <li><a href="#processgetgroups"><code>process.getgroups()</code></a></li> <li><a href="#processgetuid"><code>process.getuid()</code></a></li> <li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li> <li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li> <li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li> <li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li> <li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li> <li><span class="stability_1"><a href="#processloadenvfilepath"><code>process.loadEnvFile(path)</code></a></span></li> <li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li> <li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li> <li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li> <li><span class="stability_3"><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a></span> <ul> <li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li> </ul> </li> <li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li> <li><a href="#processpermission"><code>process.permission</code></a> <ul> <li><a href="#processpermissionhasscope-reference"><code>process.permission.has(scope[, reference])</code></a></li> </ul> </li> <li><a href="#processpid"><code>process.pid</code></a></li> <li><a href="#processplatform"><code>process.platform</code></a></li> <li><a href="#processppid"><code>process.ppid</code></a></li> <li><a href="#processrelease"><code>process.release</code></a></li> <li><a href="#processreport"><code>process.report</code></a> <ul> <li><a href="#processreportcompact"><code>process.report.compact</code></a></li> <li><a href="#processreportdirectory"><code>process.report.directory</code></a></li> <li><a href="#processreportfilename"><code>process.report.filename</code></a></li> <li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li> <li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li> <li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li> <li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li> <li><a href="#processreportsignal"><code>process.report.signal</code></a></li> <li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li> </ul> </li> <li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li> <li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li> <li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li> <li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li> <li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li> <li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li> <li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li> <li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li> <li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li> <li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li> <li><a href="#processstderr"><code>process.stderr</code></a> <ul> <li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li> </ul> </li> <li><a href="#processstdin"><code>process.stdin</code></a> <ul> <li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li> </ul> </li> <li><a href="#processstdout"><code>process.stdout</code></a> <ul> <li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li> <li><a href="#a-note-on-process-io">A note on process I/O</a></li> </ul> </li> <li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li> <li><a href="#processtitle"><code>process.title</code></a></li> <li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li> <li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li> <li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li> <li><a href="#processuptime"><code>process.uptime()</code></a></li> <li><a href="#processversion"><code>process.version</code></a></li> <li><a href="#processversions"><code>process.versions</code></a></li> <li><a href="#exit-codes">Exit codes</a></li> </ul> </li> </ul></details> <div role="main" id="apicontent"> <h2>Process<span><a class="mark" href="#process" id="process">#</a></span><a aria-hidden="true" class="legacy" id="process_process"></a></h2> <p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v20.18.0/lib/process.js">lib/process.js</a></p> <p>The <code>process</code> object provides information about, and control over, the current Node.js process.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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> <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> <p>The <code>process</code> object is an instance of <a href="events.html#class-eventemitter"><code>EventEmitter</code></a>.</p> <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> <div class="api_metadata"> <span>Added in: v0.11.12</span> </div> <p>The <code>'beforeExit'</code> event is emitted when Node.js empties its event loop and has no additional work to schedule. Normally, the Node.js process will exit when there is no work scheduled, but a listener registered on the <code>'beforeExit'</code> event can make asynchronous calls, and thereby cause the Node.js process to continue.</p> <p>The listener callback function is invoked with the value of <a href="#processexitcode_1"><code>process.exitCode</code></a> passed as the only argument.</p> <p>The <code>'beforeExit'</code> event is <em>not</em> emitted for conditions causing explicit termination, such as calling <a href="#processexitcode"><code>process.exit()</code></a> or uncaught exceptions.</p> <p>The <code>'beforeExit'</code> should <em>not</em> be used as an alternative to the <code>'exit'</code> event unless the intention is to schedule additional work.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <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); }); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <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); }); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>); <span class="hljs-comment">// Prints:</span> <span class="hljs-comment">// This message is displayed first.</span> <span class="hljs-comment">// Process beforeExit event with code: 0</span> <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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <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); }); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <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); }); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>); <span class="hljs-comment">// Prints:</span> <span class="hljs-comment">// This message is displayed first.</span> <span class="hljs-comment">// Process beforeExit event with code: 0</span> <span class="hljs-comment">// Process exit event with code: 0</span></code><button class="copy-button">copy</button></pre> <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> <div class="api_metadata"> <span>Added in: v0.7.7</span> </div> <p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a> and <a href="cluster.html">Cluster</a> documentation), the <code>'disconnect'</code> event will be emitted when the IPC channel is closed.</p> <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> <div class="api_metadata"> <span>Added in: v0.1.7</span> </div> <ul> <li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> <p>The <code>'exit'</code> event is emitted when the Node.js process is about to exit as a result of either:</p> <ul> <li>The <code>process.exit()</code> method being called explicitly;</li> <li>The Node.js event loop no longer having any additional work to perform.</li> </ul> <p>There is no way to prevent the exiting of the event loop at this point, and once all <code>'exit'</code> listeners have finished running the Node.js process will terminate.</p> <p>The listener callback function is invoked with the exit code specified either by the <a href="#processexitcode_1"><code>process.exitCode</code></a> property, or the <code>exitCode</code> argument passed to the <a href="#processexitcode"><code>process.exit()</code></a> method.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <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>); });</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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <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>); });</code><button class="copy-button">copy</button></pre> <p>Listener functions <strong>must</strong> only perform <strong>synchronous</strong> operations. The Node.js process will exit immediately after calling the <code>'exit'</code> event listeners causing any additional work still queued in the event loop to be abandoned. In the following example, for instance, the timeout will never occur:</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>); }, <span class="hljs-number">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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> { <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>); }, <span class="hljs-number">0</span>); });</code><button class="copy-button">copy</button></pre> <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> <div class="api_metadata"> <span>Added in: v0.5.10</span> </div> <ul> <li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a> a parsed JSON object or a serializable primitive value.</li> <li><code>sendHandle</code> <a href="net.html#class-netserver" class="type"><net.Server></a> | <a href="net.html#class-netsocket" class="type"><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> object, or undefined.</li> </ul> <p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a> and <a href="cluster.html">Cluster</a> documentation), the <code>'message'</code> event is emitted whenever a message sent by a parent process using <a href="child_process.html#subprocesssendmessage-sendhandle-options-callback"><code>childprocess.send()</code></a> is received by the child process.</p> <p>The message goes through serialization and parsing. The resulting message might not be the same as what is originally sent.</p> <p>If the <code>serialization</code> option was set to <code>advanced</code> used when spawning the process, the <code>message</code> argument can contain data that JSON is not able to represent. See <a href="child_process.html#advanced-serialization">Advanced serialization for <code>child_process</code></a> for more details.</p> <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> <div class="api_metadata"> <span>Added in: v10.12.0</span><span>Deprecated since: v17.6.0, v16.15.0</span> </div> <p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated</div><p></p> <ul> <li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The resolution type. One of <code>'resolve'</code> or <code>'reject'</code>.</li> <li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> The promise that resolved or rejected more than once.</li> <li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> The value with which the promise was either resolved or rejected after the original resolve.</li> </ul> <p>The <code>'multipleResolves'</code> event is emitted whenever a <code>Promise</code> has been either:</p> <ul> <li>Resolved more than once.</li> <li>Rejected more than once.</li> <li>Rejected after resolve.</li> <li>Resolved after reject.</li> </ul> <p>This is useful for tracking potential errors in an application while using the <code>Promise</code> constructor, as multiple resolutions are silently swallowed. However, the occurrence of this event does not necessarily indicate an error. For example, <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> <p>Because of the unreliability of the event in cases like the <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> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'multipleResolves'</span>, <span class="hljs-function">(<span class="hljs-params">type, promise, reason</span>) =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason); <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>)); }); <span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) { <span class="hljs-keyword">try</span> { <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> { <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>); <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</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">'Swallowed reject'</span>)); }); } <span class="hljs-keyword">catch</span> { <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>); } } <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>); <span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span> <span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span> <span class="hljs-comment">// at Promise (*)</span> <span class="hljs-comment">// at new Promise (<anonymous>)</span> <span class="hljs-comment">// at main (*)</span> <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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'multipleResolves'</span>, <span class="hljs-function">(<span class="hljs-params">type, promise, reason</span>) =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason); <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>)); }); <span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) { <span class="hljs-keyword">try</span> { <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> { <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>); <span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</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">'Swallowed reject'</span>)); }); } <span class="hljs-keyword">catch</span> { <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>); } } <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>); <span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span> <span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span> <span class="hljs-comment">// at Promise (*)</span> <span class="hljs-comment">// at new Promise (<anonymous>)</span> <span class="hljs-comment">// at main (*)</span> <span class="hljs-comment">// First call</span></code><button class="copy-button">copy</button></pre> <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> <div class="api_metadata"> <span>Added in: v1.4.1</span> </div> <ul> <li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> The late handled promise.</li> </ul> <p>The <code>'rejectionHandled'</code> event is emitted whenever a <code>Promise</code> has been rejected and 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 example) later than one turn of the Node.js event loop.</p> <p>The <code>Promise</code> object would have previously been emitted in an <code>'unhandledRejection'</code> event, but during the course of processing gained a rejection handler.</p> <p>There is no notion of a top level for a <code>Promise</code> chain at which rejections can always be handled. Being inherently asynchronous in nature, a <code>Promise</code> rejection can be handled at a future point in time, possibly much later than the event loop turn it takes for the <code>'unhandledRejection'</code> event to be emitted.</p> <p>Another way of stating this is that, unlike in synchronous code where there is an ever-growing list of unhandled exceptions, with Promises there can be a growing-and-shrinking list of unhandled rejections.</p> <p>In synchronous code, the <code>'uncaughtException'</code> event is emitted when the list of unhandled exceptions grows.</p> <p>In asynchronous code, the <code>'unhandledRejection'</code> event is emitted when the list of unhandled rejections grows, and the <code>'rejectionHandled'</code> event is emitted when the list of unhandled rejections shrinks.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>(); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> { unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason); }); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> { unhandledRejections.<span class="hljs-title function_">delete</span>(promise); });</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>); <span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>(); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> { unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason); }); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> { unhandledRejections.<span class="hljs-title function_">delete</span>(promise); });</code><button class="copy-button">copy</button></pre> <p>In this example, the <code>unhandledRejections</code> <code>Map</code> will grow and shrink over time, reflecting rejections that start unhandled and then become handled. It is possible to record such errors in an error log, either periodically (which is likely best for long-running application) or upon process exit (which is likely most convenient for scripts).</p> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v12.0.0, v10.17.0</td> <td><p>Added the <code>origin</code> argument.</p></td></tr> <tr><td>v0.1.18</td> <td><p><span>Added in: v0.1.18</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The uncaught exception.</li> <li><code>origin</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Indicates if the exception originates from an unhandled rejection or from a synchronous error. Can either be <code>'uncaughtException'</code> or <code>'unhandledRejection'</code>. The latter is used when an exception happens in a <code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and <a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the default) and the rejection is not handled, or when a rejection happens during the command line entry point's ES module static loading phase.</li> </ul> <p>The <code>'uncaughtException'</code> event is emitted when an uncaught JavaScript exception bubbles all the way back to the event loop. By default, Node.js handles such exceptions by printing the stack trace to <code>stderr</code> and exiting with code 1, overriding any previously set <a href="#processexitcode_1"><code>process.exitCode</code></a>. Adding a handler for the <code>'uncaughtException'</code> event overrides this default behavior. Alternatively, change the <a href="#processexitcode_1"><code>process.exitCode</code></a> in the <code>'uncaughtException'</code> handler which will result in the process exiting with the provided exit code. Otherwise, in the presence of such handler the process will exit with 0.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">import</span> fs <span class="hljs-keyword">from</span> <span class="hljs-string">'node:fs'</span>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtException'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> { fs.<span class="hljs-title function_">writeSync</span>( process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>, <span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> + <span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>\n`</span>, ); }); <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>); }, <span class="hljs-number">500</span>); <span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span> <span class="hljs-title function_">nonexistentFunc</span>(); <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>); <span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtException'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> { fs.<span class="hljs-title function_">writeSync</span>( process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>, <span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> + <span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>\n`</span>, ); }); <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>); }, <span class="hljs-number">500</span>); <span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span> <span class="hljs-title function_">nonexistentFunc</span>(); <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> <p>It is possible to monitor <code>'uncaughtException'</code> events without overriding the default behavior to exit the process by installing a <code>'uncaughtExceptionMonitor'</code> listener.</p> <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> <p><code>'uncaughtException'</code> is a crude mechanism for exception handling intended to be used only as a last resort. The event <em>should not</em> be used as an equivalent to <code>On Error Resume Next</code>. Unhandled exceptions inherently mean that an application is in an undefined state. Attempting to resume application code without properly recovering from the exception can cause additional unforeseen and unpredictable issues.</p> <p>Exceptions thrown from within the event handler will not be caught. Instead the process will exit with a non-zero exit code and the stack trace will be printed. This is to avoid infinite recursion.</p> <p>Attempting to resume normally after an uncaught exception can be similar to pulling out the power cord when upgrading a computer. Nine out of ten times, nothing happens. But the tenth time, the system becomes corrupted.</p> <p>The correct use of <code>'uncaughtException'</code> is to perform synchronous cleanup of allocated resources (e.g. file descriptors, handles, etc) before shutting down the process. <strong>It is not safe to resume normal operation after <code>'uncaughtException'</code>.</strong></p> <p>To restart a crashed application in a more reliable way, whether <code>'uncaughtException'</code> is emitted or not, an external monitor should be employed in a separate process to detect application failures and recover or restart as needed.</p> <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> <div class="api_metadata"> <span>Added in: v13.7.0, v12.17.0</span> </div> <ul> <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The uncaught exception.</li> <li><code>origin</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Indicates if the exception originates from an unhandled rejection or from synchronous errors. Can either be <code>'uncaughtException'</code> or <code>'unhandledRejection'</code>. The latter is used when an exception happens in a <code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and <a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the default) and the rejection is not handled, or when a rejection happens during the command line entry point's ES module static loading phase.</li> </ul> <p>The <code>'uncaughtExceptionMonitor'</code> event is emitted before an <code>'uncaughtException'</code> event is emitted or a hook installed via <a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a> is called.</p> <p>Installing an <code>'uncaughtExceptionMonitor'</code> listener does not change the behavior once an <code>'uncaughtException'</code> event is emitted. The process will still crash if no <code>'uncaughtException'</code> listener is installed.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtExceptionMonitor'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> { <span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin); }); <span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span> <span class="hljs-title function_">nonexistentFunc</span>(); <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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtExceptionMonitor'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> { <span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin); }); <span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span> <span class="hljs-title function_">nonexistentFunc</span>(); <span class="hljs-comment">// Still crashes Node.js</span></code><button class="copy-button">copy</button></pre> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v7.0.0</td> <td><p>Not handling <code>Promise</code> rejections is deprecated.</p></td></tr> <tr><td>v6.6.0</td> <td><p>Unhandled <code>Promise</code> rejections will now emit a process warning.</p></td></tr> <tr><td>v1.4.1</td> <td><p><span>Added in: v1.4.1</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> The object with which the promise was rejected (typically an <a href="errors.html#class-error"><code>Error</code></a> object).</li> <li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> The rejected promise.</li> </ul> <p>The <code>'unhandledRejection'</code> event is emitted whenever a <code>Promise</code> is rejected and no error handler is attached to the promise within a turn of the event loop. When programming with Promises, exceptions are encapsulated as "rejected promises". 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 are propagated through a <code>Promise</code> chain. The <code>'unhandledRejection'</code> event is useful for detecting and keeping track of promises that were rejected whose rejections have not yet been handled.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> { <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); <span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span> }); somePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> { <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> }); <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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> { <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); <span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span> }); somePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> { <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> }); <span class="hljs-comment">// No `.catch()` or `.then()`</span></code><button class="copy-button">copy</button></pre> <p>The following will also trigger the <code>'unhandledRejection'</code> event to be emitted:</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) { <span class="hljs-comment">// Initially set the loaded status to a rejected promise</span> <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>)); } <span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>(); <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>); <span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) { <span class="hljs-comment">// Initially set the loaded status to a rejected promise</span> <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>)); } <span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>(); <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> <p>In this example case, it is possible to track the rejection as a developer error as would typically be the case for other <code>'unhandledRejection'</code> events. To address such failures, a non-operational <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 <code>resource.loaded</code>, which would prevent the <code>'unhandledRejection'</code> event from being emitted.</p> <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> <div class="api_metadata"> <span>Added in: v6.0.0</span> </div> <ul> <li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> Key properties of the warning are: <ul> <li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The name of the warning. <strong>Default:</strong> <code>'Warning'</code>.</li> <li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A system-provided description of the warning.</li> <li><code>stack</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A stack trace to the location in the code where the warning was issued.</li> </ul> </li> </ul> <p>The <code>'warning'</code> event is emitted whenever Node.js emits a process warning.</p> <p>A process warning is similar to an error in that it describes exceptional conditions that are being brought to the user's attention. However, warnings are not part of the normal Node.js and JavaScript error handling flow. Node.js can emit warnings whenever it detects bad coding practices that could lead to sub-optimal application performance, bugs, or security vulnerabilities.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> { <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> <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> <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> });</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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> { <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> <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> <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> });</code><button class="copy-button">copy</button></pre> <p>By default, Node.js will print process warnings to <code>stderr</code>. The <code>--no-warnings</code> command-line option can be used to suppress the default console output but the <code>'warning'</code> event will still be emitted by the <code>process</code> object. Currently, it is not possible to suppress specific warning types other than deprecation warnings. To suppress deprecation warnings, check out the <a href="cli.html#--no-deprecation"><code>--no-deprecation</code></a> flag.</p> <p>The following example illustrates the warning that is printed to <code>stderr</code> when too many listeners have been added to an event:</p> <pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">(node:38638) MaxListenersExceededWarning: Possible EventEmitter memory leak</span> detected. 2 foo listeners added. Use emitter.setMaxListeners() to increase limit</code> <button class="copy-button">copy</button></pre> <p>In contrast, the following example turns off the default warning output and adds a custom handler to the <code>'warning'</code> event:</p> <pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node --no-warnings</span> <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> <span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span> <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> <p>The <code>--trace-warnings</code> command-line option can be used to have the default console output for warnings include the full stack trace of the warning.</p> <p>Launching Node.js using the <code>--throw-deprecation</code> command-line flag will cause custom deprecation warnings to be thrown as exceptions.</p> <p>Using the <code>--trace-deprecation</code> command-line flag will cause the custom deprecation to be printed to <code>stderr</code> along with the stack trace.</p> <p>Using the <code>--no-deprecation</code> command-line flag will suppress all reporting of the custom deprecation.</p> <p>The <code>*-deprecation</code> command-line flags only affect warnings that use the name <code>'DeprecationWarning'</code>.</p> <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> <p>See the <a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning()</code></a> method for issuing custom or application-specific warnings.</p> <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> <p>There are no strict guidelines for warning types (as identified by the <code>name</code> property) emitted by Node.js. New types of warnings can be added at any time. A few of the warning types that are most common include:</p> <ul> <li><code>'DeprecationWarning'</code> - Indicates use of a deprecated Node.js API or feature. Such warnings must include a <code>'code'</code> property identifying the <a href="deprecations.html">deprecation code</a>.</li> <li><code>'ExperimentalWarning'</code> - Indicates use of an experimental Node.js API or feature. Such features must be used with caution as they may change at any time and are not subject to the same strict semantic-versioning and long-term support policies as supported features.</li> <li><code>'MaxListenersExceededWarning'</code> - Indicates that too many listeners for a given event have been registered on either an <code>EventEmitter</code> or <code>EventTarget</code>. This is often an indication of a memory leak.</li> <li><code>'TimeoutOverflowWarning'</code> - Indicates that a numeric value that cannot fit within a 32-bit signed integer has been provided to either the <code>setTimeout()</code> or <code>setInterval()</code> functions.</li> <li><code>'UnsupportedWarning'</code> - Indicates use of an unsupported option or feature that will be ignored rather than treated as an error. One example is use of the HTTP response status message when using the HTTP/2 compatibility API.</li> </ul> <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> <div class="api_metadata"> <span>Added in: v16.2.0, v14.18.0</span> </div> <ul> <li><code>worker</code> <a href="worker_threads.html#class-worker" class="type"><Worker></a> The <a href="worker_threads.html#class-worker" class="type"><Worker></a> that was created.</li> </ul> <p>The <code>'worker'</code> event is emitted after a new <a href="worker_threads.html#class-worker" class="type"><Worker></a> thread has been created.</p> <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> <p>Signal events will be emitted when the Node.js process receives a signal. Please refer 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 <code>'SIGINT'</code>, <code>'SIGHUP'</code>, etc.</p> <p>Signals are not available on <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> <p>The signal handler will receive the signal's name (<code>'SIGINT'</code>, <code>'SIGTERM'</code>, etc.) as the first argument.</p> <p>The name of each event will be the uppercase common name for the signal (e.g. <code>'SIGINT'</code> for <code>SIGINT</code> signals).</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span> process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>(); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> { <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>); }); <span class="hljs-comment">// Using a single function to handle multiple signals</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) { <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>); } process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle); process.<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>); <span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span> process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>(); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> { <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>); }); <span class="hljs-comment">// Using a single function to handle multiple signals</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) { <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>); } process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGTERM'</span>, handle);</code><button class="copy-button">copy</button></pre> <ul> <li><code>'SIGUSR1'</code> is reserved by Node.js to start the <a href="debugger.html">debugger</a>. It's possible to install a listener but doing so might interfere with the debugger.</li> <li><code>'SIGTERM'</code> and <code>'SIGINT'</code> have default handlers on non-Windows platforms that reset the terminal mode before exiting with code <code>128 + signal number</code>. If one of these signals has a listener installed, its default behavior will be removed (Node.js will no longer exit).</li> <li><code>'SIGPIPE'</code> is ignored by default. It can have a listener installed.</li> <li><code>'SIGHUP'</code> is generated on Windows when the console window is closed, and on other 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 listener installed, however Node.js will be unconditionally terminated by Windows about 10 seconds later. On non-Windows platforms, the default behavior of <code>SIGHUP</code> is to terminate Node.js, but once a listener has been installed its default behavior will be removed.</li> <li><code>'SIGTERM'</code> is not supported on Windows, it can be listened on.</li> <li><code>'SIGINT'</code> from the terminal is supported on all platforms, and can usually be generated with <kbd>Ctrl</kbd>+<kbd>C</kbd> (though this may be configurable). It is not generated when <a href="tty.html#readstreamsetrawmodemode">terminal raw mode</a> is enabled and <kbd>Ctrl</kbd>+<kbd>C</kbd> is used.</li> <li><code>'SIGBREAK'</code> is delivered on Windows when <kbd>Ctrl</kbd>+<kbd>Break</kbd> is pressed. On non-Windows platforms, it can be listened on, but there is no way to send or generate it.</li> <li><code>'SIGWINCH'</code> is delivered when the console has been resized. On Windows, this will only happen on write to the console when the cursor is being moved, or when a readable tty is used in raw mode.</li> <li><code>'SIGKILL'</code> cannot have a listener installed, it will unconditionally terminate Node.js on all platforms.</li> <li><code>'SIGSTOP'</code> cannot have a listener installed.</li> <li><code>'SIGBUS'</code>, <code>'SIGFPE'</code>, <code>'SIGSEGV'</code>, and <code>'SIGILL'</code>, when not raised artificially 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 which it is not safe to call JS listeners. Doing so might cause the process to stop responding.</li> <li><code>0</code> can be sent to test for the existence of a process, it has no effect if the process exists, but will throw an error if the process does not exist.</li> </ul> <p>Windows does not support signals so has no equivalent to termination by signal, but Node.js offers some emulation with <a href="#processkillpid-signal"><code>process.kill()</code></a>, and <a href="child_process.html#subprocesskillsignal"><code>subprocess.kill()</code></a>:</p> <ul> <li>Sending <code>SIGINT</code>, <code>SIGTERM</code>, and <code>SIGKILL</code> will cause the unconditional termination of the target process, and afterwards, subprocess will report that the process was terminated by signal.</li> <li>Sending signal <code>0</code> can be used as a platform independent way to test for the existence of a process.</li> </ul> </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> <div class="api_metadata"> <span>Added in: v0.7.0</span> </div> <p>The <code>process.abort()</code> method causes the Node.js process to exit immediately and generate a core file.</p> <p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <span>Added in: v10.10.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set" class="type"><Set></a></li> </ul> <p>The <code>process.allowedNodeEnvironmentFlags</code> property is a special, read-only <code>Set</code> of flags allowable within the <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a> environment variable.</p> <p><code>process.allowedNodeEnvironmentFlags</code> extends <code>Set</code>, but overrides <code>Set.prototype.has</code> to recognize several different possible flag representations. <code>process.allowedNodeEnvironmentFlags.has()</code> will return <code>true</code> in the following cases:</p> <ul> <li>Flags may omit leading single (<code>-</code>) or double (<code>--</code>) dashes; e.g., <code>inspect-brk</code> for <code>--inspect-brk</code>, or <code>r</code> for <code>-r</code>.</li> <li>Flags passed through to V8 (as listed in <code>--v8-options</code>) may replace one or more <em>non-leading</em> dashes for an underscore, or vice-versa; e.g., <code>--perf_basic_prof</code>, <code>--perf-basic-prof</code>, <code>--perf_basic-prof</code>, etc.</li> <li>Flags may contain one or more equals (<code>=</code>) characters; all characters after and including the first equals will be ignored; e.g., <code>--stack-trace-limit=100</code>.</li> <li>Flags <em>must</em> be allowable within <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a>.</li> </ul> <p>When iterating over <code>process.allowedNodeEnvironmentFlags</code>, flags will appear only <em>once</em>; each will begin with one or more dashes. Flags passed through to V8 will contain underscores instead of non-leading dashes:</p> <pre class="with-64-chars"><input class="js-flavor-toggle" 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>; allowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> { <span class="hljs-comment">// -r</span> <span class="hljs-comment">// --inspect-brk</span> <span class="hljs-comment">// --abort_on_uncaught_exception</span> <span class="hljs-comment">// ...</span> });</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>); allowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> { <span class="hljs-comment">// -r</span> <span class="hljs-comment">// --inspect-brk</span> <span class="hljs-comment">// --abort_on_uncaught_exception</span> <span class="hljs-comment">// ...</span> });</code><button class="copy-button">copy</button></pre> <p>The methods <code>add()</code>, <code>clear()</code>, and <code>delete()</code> of <code>process.allowedNodeEnvironmentFlags</code> do nothing, and will fail silently.</p> <p>If Node.js was compiled <em>without</em> <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a> support (shown in <a href="#processconfig"><code>process.config</code></a>), <code>process.allowedNodeEnvironmentFlags</code> will contain what <em>would have</em> been allowable.</p> </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> <div class="api_metadata"> <span>Added in: v0.5.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The operating system CPU architecture for which the Node.js binary was compiled. Possible values are: <code>'arm'</code>, <code>'arm64'</code>, <code>'ia32'</code>, <code>'loong64'</code>, <code>'mips'</code>, <code>'mipsel'</code>, <code>'ppc'</code>, <code>'ppc64'</code>, <code>'riscv64'</code>, <code>'s390'</code>, <code>'s390x'</code>, and <code>'x64'</code>.</p> <pre class="with-41-chars"><input class="js-flavor-toggle" 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>; <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>); <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> </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> <div class="api_metadata"> <span>Added in: v0.1.27</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> </ul> <p>The <code>process.argv</code> property returns an array containing the command-line arguments passed when the Node.js process was launched. The first element will be <a href="#processexecpath"><code>process.execPath</code></a>. See <code>process.argv0</code> if access to the original value of <code>argv[0]</code> is needed. The second element will be the path to the JavaScript file being executed. The remaining elements will be any additional command-line arguments.</p> <p>For example, assuming the following script for <code>process-args.js</code>:</p> <pre class="with-41-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// print process.argv</span> argv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> { <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>); });</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>); <span class="hljs-comment">// print process.argv</span> argv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> { <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>); });</code><button class="copy-button">copy</button></pre> <p>Launching the Node.js process as:</p> <pre><code class="language-bash">node process-args.js one two=three four</code> <button class="copy-button">copy</button></pre> <p>Would generate the output:</p> <pre><code class="language-text">0: /usr/local/bin/node 1: /Users/mjr/work/node/process-args.js 2: one 3: two=three 4: four</code> <button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v6.4.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.argv0</code> property stores a read-only copy of the original value of <code>argv[0]</code> passed when Node.js starts.</p> <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> <span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv[0]</span> '/Volumes/code/external/node/out/Release/node' <span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv0</span> 'customArgv0'</code> <button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v14.0.0</td> <td><p>The object no longer accidentally exposes native C++ bindings.</p></td></tr> <tr><td>v7.1.0</td> <td><p><span>Added in: v7.1.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>If the Node.js process was spawned with an IPC channel (see the <a href="child_process.html">Child Process</a> documentation), the <code>process.channel</code> property is a reference to the IPC channel. If no IPC channel exists, this property is <code>undefined</code>.</p> <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> <div class="api_metadata"> <span>Added in: v7.1.0</span> </div> <p>This method makes the IPC channel keep the event loop of the process running if <code>.unref()</code> has been called before.</p> <p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code> listeners on the <code>process</code> object. However, this method can be used to explicitly request a specific behavior.</p> <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> <div class="api_metadata"> <span>Added in: v7.1.0</span> </div> <p>This method makes the IPC channel not keep the event loop of the process running, and lets it finish even while the channel is open.</p> <p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code> listeners on the <code>process</code> object. However, this method can be used to explicitly request a specific behavior.</p> </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> <div class="api_metadata"> <span>Added in: v0.1.17</span> </div> <ul> <li><code>directory</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.chdir()</code> method changes the current working directory of the Node.js process or throws an exception if doing so fails (for instance, if the specified <code>directory</code> does not exist).</p> <pre class="with-47-chars"><input class="js-flavor-toggle" 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>; <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>); <span class="hljs-keyword">try</span> { <span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); }</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>); <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>); <span class="hljs-keyword">try</span> { <span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); }</code><button class="copy-button">copy</button></pre> <p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v19.0.0</td> <td><p>The <code>process.config</code> object is now frozen.</p></td></tr> <tr><td>v16.0.0</td> <td><p>Modifying process.config has been deprecated.</p></td></tr> <tr><td>v0.7.7</td> <td><p><span>Added in: v0.7.7</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>The <code>process.config</code> property returns a frozen <code>Object</code> containing the JavaScript representation of the configure options used to compile the current Node.js executable. This is the same as the <code>config.gypi</code> file that was produced when running the <code>./configure</code> script.</p> <p>An example of the possible output looks like:</p> <!-- eslint-skip --> <pre><code class="language-js">{ <span class="hljs-attr">target_defaults</span>: { <span class="hljs-attr">cflags</span>: [], <span class="hljs-attr">default_configuration</span>: <span class="hljs-string">'Release'</span>, <span class="hljs-attr">defines</span>: [], <span class="hljs-attr">include_dirs</span>: [], <span class="hljs-attr">libraries</span>: [] }, <span class="hljs-attr">variables</span>: { <span class="hljs-attr">host_arch</span>: <span class="hljs-string">'x64'</span>, <span class="hljs-attr">napi_build_version</span>: <span class="hljs-number">5</span>, <span class="hljs-attr">node_install_npm</span>: <span class="hljs-string">'true'</span>, <span class="hljs-attr">node_prefix</span>: <span class="hljs-string">''</span>, <span class="hljs-attr">node_shared_cares</span>: <span class="hljs-string">'false'</span>, <span class="hljs-attr">node_shared_http_parser</span>: <span class="hljs-string">'false'</span>, <span class="hljs-attr">node_shared_libuv</span>: <span class="hljs-string">'false'</span>, <span class="hljs-attr">node_shared_zlib</span>: <span class="hljs-string">'false'</span>, <span class="hljs-attr">node_use_openssl</span>: <span class="hljs-string">'true'</span>, <span class="hljs-attr">node_shared_openssl</span>: <span class="hljs-string">'false'</span>, <span class="hljs-attr">strict_aliasing</span>: <span class="hljs-string">'true'</span>, <span class="hljs-attr">target_arch</span>: <span class="hljs-string">'x64'</span>, <span class="hljs-attr">v8_use_snapshot</span>: <span class="hljs-number">1</span> } }</code> <button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.7.2</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a> and <a href="cluster.html">Cluster</a> documentation), the <code>process.connected</code> property will return <code>true</code> so long as the IPC channel is connected and will return <code>false</code> after <code>process.disconnect()</code> is called.</p> <p>Once <code>process.connected</code> is <code>false</code>, it is no longer possible to send messages over the IPC channel using <code>process.send()</code>.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v20.13.0</td> <td><p>Aligned return value with <code>uv_get_constrained_memory</code>.</p></td></tr> <tr><td>v19.6.0, v18.15.0</td> <td><p><span>Added in: v19.6.0, v18.15.0</span></p></td></tr> </tbody></table> </details> </div> <p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> </ul> <p>Gets the amount of memory available to the process (in bytes) based on limits imposed by the OS. If there is no such constraint, or the constraint is unknown, <code>0</code> is returned.</p> <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 information.</p> </section><section><h3><code>process.availableMemory()</code><span><a class="mark" href="#processavailablememory" id="processavailablememory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_availablememory"></a></h3> <div class="api_metadata"> <span>Added in: v20.13.0</span> </div> <p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> </ul> <p>Gets the amount of free memory that is still available to the process (in bytes).</p> <p>See <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_get_available_memory"><code>uv_get_available_memory</code></a> for more information.</p> </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> <div class="api_metadata"> <span>Added in: v6.1.0</span> </div> <ul> <li><code>previousValue</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> A previous return value from calling <code>process.cpuUsage()</code></li> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> <ul> <li><code>user</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> <li><code>system</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> </li> </ul> <p>The <code>process.cpuUsage()</code> method returns the user and system CPU time usage of the current process, in an object with properties <code>user</code> and <code>system</code>, whose values are microsecond values (millionth of a second). These values measure time spent in user and system code respectively, and may end up being greater than actual elapsed time if multiple CPU cores are performing work for this process.</p> <p>The result of a previous call to <code>process.cpuUsage()</code> can be passed as the argument to the function, to get a diff reading.</p> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>(); <span class="hljs-comment">// { user: 38579, system: 6986 }</span> <span class="hljs-comment">// spin the CPU for 500 milliseconds</span> <span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>(); <span class="hljs-keyword">while</span> (<span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>() - now < <span class="hljs-number">500</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage)); <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>); <span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>(); <span class="hljs-comment">// { user: 38579, system: 6986 }</span> <span class="hljs-comment">// spin the CPU for 500 milliseconds</span> <span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>(); <span class="hljs-keyword">while</span> (<span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>() - now < <span class="hljs-number">500</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage)); <span class="hljs-comment">// { user: 514883, system: 11226 }</span></code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.1.8</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.cwd()</code> method returns the current working directory of the Node.js process.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <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>); <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> </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> <div class="api_metadata"> <span>Added in: v0.7.2</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> </ul> <p>The port used by the Node.js debugger when enabled.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<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>); process.<span class="hljs-property">debugPort</span> = <span class="hljs-number">5858</span>;</code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.7.2</span> </div> <p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a> and <a href="cluster.html">Cluster</a> documentation), the <code>process.disconnect()</code> method will close the IPC channel to the parent process, allowing the child process to exit gracefully once there are no other connections keeping it alive.</p> <p>The effect of calling <code>process.disconnect()</code> is the same as calling <a href="child_process.html#subprocessdisconnect"><code>ChildProcess.disconnect()</code></a> from the parent process.</p> <p>If the Node.js process was not spawned with an IPC channel, <code>process.disconnect()</code> will be <code>undefined</code>.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v9.0.0</td> <td><p>Added support for the <code>flags</code> argument.</p></td></tr> <tr><td>v0.1.16</td> <td><p><span>Added in: v0.1.16</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><code>module</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> <li><code>filename</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> <li><code>flags</code> <a href="os.html#dlopen-constants" class="type"><os.constants.dlopen></a> <strong>Default:</strong> <code>os.constants.dlopen.RTLD_LAZY</code></li> </ul> <p>The <code>process.dlopen()</code> method allows dynamically loading shared objects. It is primarily used by <code>require()</code> to load C++ Addons, and should not be used directly, except in special cases. In other words, <a href="globals.html#require"><code>require()</code></a> should be preferred over <code>process.dlopen()</code> unless there are specific reasons such as custom dlopen flags or loading from ES modules.</p> <p>The <code>flags</code> argument is an integer that allows to specify dlopen behavior. See the <a href="os.html#dlopen-constants"><code>os.constants.dlopen</code></a> documentation for details.</p> <p>An important requirement when calling <code>process.dlopen()</code> is that the <code>module</code> instance must be passed. Functions exported by the C++ Addon are then accessible via <code>module.exports</code>.</p> <p>The example below shows how to load a C++ Addon, named <code>local.node</code>, that exports a <code>foo</code> function. All the symbols are loaded before the call returns, by passing the <code>RTLD_NOW</code> constant. In this example the constant is assumed to be available.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">import</span> { constants } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:os'</span>; <span class="hljs-keyword">import</span> { fileURLToPath } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:url'</span>; <span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} }; <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>)), constants.<span class="hljs-property">dlopen</span>.<span class="hljs-property">RTLD_NOW</span>); <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>); <span class="hljs-keyword">const</span> { constants } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:os'</span>); <span class="hljs-keyword">const</span> { join } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:path'</span>); <span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} }; <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>); <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> </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> <div class="api_metadata"> <span>Added in: v8.0.0</span> </div> <ul> <li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The warning to emit.</li> <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> <ul> <li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> When <code>warning</code> is a <code>String</code>, <code>type</code> is the name to use for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li> <li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A unique identifier for the warning instance being emitted.</li> <li><code>ctor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> When <code>warning</code> is a <code>String</code>, <code>ctor</code> is an optional function used to limit the generated stack trace. <strong>Default:</strong> <code>process.emitWarning</code>.</li> <li><code>detail</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Additional text to include with the error.</li> </ul> </li> </ul> <p>The <code>process.emitWarning()</code> method can be used to emit custom or application specific process warnings. These can be listened for by adding a handler to the <a href="#event-warning"><code>'warning'</code></a> event.</p> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// Emit a warning with a code and additional detail.</span> <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, { <span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>, <span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>, }); <span class="hljs-comment">// Emits:</span> <span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span> <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>); <span class="hljs-comment">// Emit a warning with a code and additional detail.</span> <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, { <span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>, <span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>, }); <span class="hljs-comment">// Emits:</span> <span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span> <span class="hljs-comment">// This is some additional information</span></code><button class="copy-button">copy</button></pre> <p>In this example, an <code>Error</code> object is generated internally by <code>process.emitWarning()</code> and passed through to the <a href="#event-warning"><code>'warning'</code></a> handler.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> { <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> <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> <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> <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> <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> });</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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> { <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> <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> <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> <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> <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> });</code><button class="copy-button">copy</button></pre> <p>If <code>warning</code> is passed as an <code>Error</code> object, the <code>options</code> argument is ignored.</p> </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> <div class="api_metadata"> <span>Added in: v6.0.0</span> </div> <ul> <li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The warning to emit.</li> <li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> When <code>warning</code> is a <code>String</code>, <code>type</code> is the name to use for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li> <li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A unique identifier for the warning instance being emitted.</li> <li><code>ctor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> When <code>warning</code> is a <code>String</code>, <code>ctor</code> is an optional function used to limit the generated stack trace. <strong>Default:</strong> <code>process.emitWarning</code>.</li> </ul> <p>The <code>process.emitWarning()</code> method can be used to emit custom or application specific process warnings. These can be listened for by adding a handler to the <a href="#event-warning"><code>'warning'</code></a> event.</p> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// Emit a warning using a string.</span> <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>); <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>); <span class="hljs-comment">// Emit a warning using a string.</span> <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>); <span class="hljs-comment">// Emits: (node: 56338) Warning: Something happened!</span></code><button class="copy-button">copy</button></pre> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// Emit a warning using a string and a type.</span> <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>); <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>); <span class="hljs-comment">// Emit a warning using a string and a type.</span> <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>); <span class="hljs-comment">// Emits: (node:56338) CustomWarning: Something Happened!</span></code><button class="copy-button">copy</button></pre> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <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>); <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>); process.<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, <span class="hljs-string">'CustomWarning'</span>, <span class="hljs-string">'WARN001'</span>); <span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre> <p>In each of the previous examples, an <code>Error</code> object is generated internally by <code>process.emitWarning()</code> and passed through to the <a href="#event-warning"><code>'warning'</code></a> handler.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>); });</code><button class="copy-button">copy</button></pre> <p>If <code>warning</code> is passed as an <code>Error</code> object, it will be passed through to the <code>'warning'</code> event handler unmodified (and the optional <code>type</code>, <code>code</code> and <code>ctor</code> arguments will be ignored):</p> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// Emit a warning using an Error object.</span> <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>); <span class="hljs-comment">// Use the Error name property to specify the type name</span> myWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>; myWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>; <span class="hljs-title function_">emitWarning</span>(myWarning); <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>); <span class="hljs-comment">// Emit a warning using an Error object.</span> <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>); <span class="hljs-comment">// Use the Error name property to specify the type name</span> myWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>; myWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>; <span class="hljs-title function_">emitWarning</span>(myWarning); <span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre> <p>A <code>TypeError</code> is thrown if <code>warning</code> is anything other than a string or <code>Error</code> object.</p> <p>While process warnings use <code>Error</code> objects, the process warning mechanism is <strong>not</strong> a replacement for normal error handling mechanisms.</p> <p>The following additional handling is implemented if the warning <code>type</code> is <code>'DeprecationWarning'</code>:</p> <ul> <li>If the <code>--throw-deprecation</code> command-line flag is used, the deprecation warning is thrown as an exception rather than being emitted as an event.</li> <li>If the <code>--no-deprecation</code> command-line flag is used, the deprecation warning is suppressed.</li> <li>If the <code>--trace-deprecation</code> command-line flag is used, the deprecation warning is printed to <code>stderr</code> along with the full stack trace.</li> </ul> <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> <p>As a best practice, warnings should be emitted only once per process. To do so, place the <code>emitWarning()</code> behind a boolean.</p> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) { <span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) { emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>; <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>); } } <span class="hljs-title function_">emitMyWarning</span>(); <span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span> <span class="hljs-title function_">emitMyWarning</span>(); <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>); <span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) { <span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) { emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>; <span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>); } } <span class="hljs-title function_">emitMyWarning</span>(); <span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span> <span class="hljs-title function_">emitMyWarning</span>(); <span class="hljs-comment">// Emits nothing</span></code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v11.14.0</td> <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> <tr><td>v10.0.0</td> <td><p>Implicit conversion of variable value to string is deprecated.</p></td></tr> <tr><td>v0.1.27</td> <td><p><span>Added in: v0.1.27</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>The <code>process.env</code> property returns an object containing the user environment. See <a href="http://man7.org/linux/man-pages/man7/environ.7.html"><code>environ(7)</code></a>.</p> <p>An example of this object looks like:</p> <!-- eslint-skip --> <pre><code class="language-js">{ <span class="hljs-attr">TERM</span>: <span class="hljs-string">'xterm-256color'</span>, <span class="hljs-attr">SHELL</span>: <span class="hljs-string">'/usr/local/bin/bash'</span>, <span class="hljs-attr">USER</span>: <span class="hljs-string">'maciej'</span>, <span class="hljs-attr">PATH</span>: <span class="hljs-string">'~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'</span>, <span class="hljs-attr">PWD</span>: <span class="hljs-string">'/Users/maciej'</span>, <span class="hljs-attr">EDITOR</span>: <span class="hljs-string">'vim'</span>, <span class="hljs-attr">SHLVL</span>: <span class="hljs-string">'1'</span>, <span class="hljs-attr">HOME</span>: <span class="hljs-string">'/Users/maciej'</span>, <span class="hljs-attr">LOGNAME</span>: <span class="hljs-string">'maciej'</span>, <span class="hljs-attr">_</span>: <span class="hljs-string">'/usr/local/bin/node'</span> }</code> <button class="copy-button">copy</button></pre> <p>It is possible to modify this object, but such modifications will not be reflected outside the Node.js process, or (unless explicitly requested) to other <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads. In other words, the following example would not work:</p> <pre><code class="language-bash">node -e <span class="hljs-string">'process.env.foo = "bar"'</span> && <span class="hljs-built_in">echo</span> <span class="hljs-variable">$foo</span></code> <button class="copy-button">copy</button></pre> <p>While the following will:</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; env.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>; <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>); env.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>; <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> <p>Assigning a property on <code>process.env</code> will implicitly convert the value to a string. <strong>This behavior is deprecated.</strong> Future versions of Node.js may throw an error when the value is not a string, number, or boolean.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; env.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>); <span class="hljs-comment">// => 'null'</span> env.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>); <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>); env.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>); <span class="hljs-comment">// => 'null'</span> env.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>); <span class="hljs-comment">// => 'undefined'</span></code><button class="copy-button">copy</button></pre> <p>Use <code>delete</code> to delete a property from <code>process.env</code>.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>; <span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>); <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>); env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>; <span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>); <span class="hljs-comment">// => undefined</span></code><button class="copy-button">copy</button></pre> <p>On Windows operating systems, environment variables are case-insensitive.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>); <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>); env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>); <span class="hljs-comment">// => 1</span></code><button class="copy-button">copy</button></pre> <p>Unless explicitly specified when creating a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance, each <a href="worker_threads.html#class-worker"><code>Worker</code></a> thread has its own copy of <code>process.env</code>, based on its parent thread's <code>process.env</code>, or whatever was specified as the <code>env</code> option to the <a href="worker_threads.html#class-worker"><code>Worker</code></a> constructor. Changes to <code>process.env</code> will not be visible across <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, and only the main thread can make changes that are visible to the operating system or to native add-ons. On Windows, a copy of <code>process.env</code> on a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance operates in a case-sensitive manner unlike the main thread.</p> </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> <div class="api_metadata"> <span>Added in: v0.7.7</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> </ul> <p>The <code>process.execArgv</code> property returns the set of Node.js-specific command-line options passed when the Node.js process was launched. These options do not appear in the array returned by the <a href="#processargv"><code>process.argv</code></a> property, and do not include the Node.js executable, the name of the script, or any options following the script name. These options are useful in order to spawn child processes with the same execution environment as the parent.</p> <pre><code class="language-bash">node --icu-data-dir=./foo --require ./bar.js script.js --version</code> <button class="copy-button">copy</button></pre> <p>Results in <code>process.execArgv</code>:</p> <pre><code class="language-json"><span class="hljs-punctuation">[</span><span class="hljs-string">"--icu-data-dir=./foo"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"--require"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"./bar.js"</span><span class="hljs-punctuation">]</span></code> <button class="copy-button">copy</button></pre> <p>And <code>process.argv</code>:</p> <!-- eslint-disable @stylistic/js/semi --> <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> <p>Refer to <a href="worker_threads.html#new-workerfilename-options"><code>Worker</code> constructor</a> for the detailed behavior of worker threads with this property.</p> </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> <div class="api_metadata"> <span>Added in: v0.1.100</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.execPath</code> property returns the absolute pathname of the executable that started the Node.js process. Symbolic links, if any, are resolved.</p> <!-- eslint-disable @stylistic/js/semi --> <pre><code class="language-js"><span class="hljs-string">'/usr/local/bin/node'</span></code> <button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v20.0.0</td> <td><p>Only accepts a code of type number, or of type string if it represents an integer.</p></td></tr> <tr><td>v0.1.13</td> <td><p><span>Added in: v0.1.13</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> The exit code. For string type, only integer strings (e.g.,'1') are allowed. <strong>Default:</strong> <code>0</code>.</li> </ul> <p>The <code>process.exit()</code> method instructs Node.js to terminate the process synchronously with an exit status of <code>code</code>. If <code>code</code> is omitted, exit uses either the 'success' code <code>0</code> or the value of <code>process.exitCode</code> if it has been set. Node.js will not terminate until all the <a href="#event-exit"><code>'exit'</code></a> event listeners are called.</p> <p>To exit with a 'failure' code:</p> <pre class="with-41-chars"><input class="js-flavor-toggle" 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>; <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>); <span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);</code><button class="copy-button">copy</button></pre> <p>The shell that executed Node.js should see the exit code as <code>1</code>.</p> <p>Calling <code>process.exit()</code> will force the process to exit as quickly as possible even if there are still asynchronous operations pending that have not yet completed fully, including I/O operations to <code>process.stdout</code> and <code>process.stderr</code>.</p> <p>In most situations, it is not actually necessary to call <code>process.exit()</code> explicitly. The Node.js process will exit on its own <em>if there is no additional work pending</em> in the event loop. The <code>process.exitCode</code> property can be set to tell the process which exit code to use when the process exits gracefully.</p> <p>For instance, the following example illustrates a <em>misuse</em> of the <code>process.exit()</code> method that could lead to data printed to stdout being truncated and lost:</p> <pre class="with-41-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// This is an example of what *not* to do:</span> <span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) { <span class="hljs-title function_">printUsageToStdout</span>(); <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>); <span class="hljs-comment">// This is an example of what *not* to do:</span> <span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) { <span class="hljs-title function_">printUsageToStdout</span>(); <span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>); }</code><button class="copy-button">copy</button></pre> <p>The reason this is problematic is because writes to <code>process.stdout</code> in Node.js are sometimes <em>asynchronous</em> and may occur over multiple ticks of the Node.js event loop. Calling <code>process.exit()</code>, however, forces the process to exit <em>before</em> those additional writes to <code>stdout</code> can be performed.</p> <p>Rather than calling <code>process.exit()</code> directly, the code <em>should</em> set the <code>process.exitCode</code> and allow the process to exit naturally by avoiding scheduling any additional work for the event loop:</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-comment">// How to properly set the exit code while letting</span> <span class="hljs-comment">// the process exit gracefully.</span> <span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) { <span class="hljs-title function_">printUsageToStdout</span>(); process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</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>); <span class="hljs-comment">// How to properly set the exit code while letting</span> <span class="hljs-comment">// the process exit gracefully.</span> <span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) { <span class="hljs-title function_">printUsageToStdout</span>(); process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>; }</code><button class="copy-button">copy</button></pre> <p>If it is necessary to terminate the Node.js process due to an error condition, throwing an <em>uncaught</em> error and allowing the process to terminate accordingly is safer than calling <code>process.exit()</code>.</p> <p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, this function stops the current thread rather than the current process.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v20.0.0</td> <td><p>Only accepts a code of type number, or of type string if it represents an integer.</p></td></tr> <tr><td>v0.11.8</td> <td><p><span>Added in: v0.11.8</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> The exit code. For string type, only integer strings (e.g.,'1') are allowed. <strong>Default:</strong> <code>undefined</code>.</li> </ul> <p>A number which will be the process exit code, when the process either exits gracefully, or is exited via <a href="#processexitcode"><code>process.exit()</code></a> without specifying a code.</p> <p>Specifying a code to <a href="#processexitcode"><code>process.exit(code)</code></a> will override any previous setting of <code>process.exitCode</code>.</p> </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> <div class="api_metadata"> <span>Added in: v17.3.0, v16.14.0</span> </div> <p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> </ul> <p>The <code>process.getActiveResourcesInfo()</code> method returns an array of strings containing the types of the active resources that are currently keeping the event loop alive.</p> <pre class="with-59-chars"><input class="js-flavor-toggle" 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>; <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>; <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>()); <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>); <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>()); <span class="hljs-comment">// Prints:</span> <span class="hljs-comment">// Before: [ 'CloseReq', 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span> <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>); <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>); <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>()); <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>); <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>()); <span class="hljs-comment">// Prints:</span> <span class="hljs-comment">// Before: [ 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span> <span class="hljs-comment">// After: [ 'TTYWrap', 'TTYWrap', 'TTYWrap', 'Timeout' ]</span></code><button class="copy-button">copy</button></pre> </section><section><h3><code>process.getBuiltinModule(id)</code><span><a class="mark" href="#processgetbuiltinmoduleid" id="processgetbuiltinmoduleid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getbuiltinmodule_id"></a></h3> <div class="api_metadata"> <span>Added in: v20.16.0</span> </div> <ul> <li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> ID of the built-in module being requested.</li> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a></li> </ul> <p><code>process.getBuiltinModule(id)</code> provides a way to load built-in modules in a globally available function. ES Modules that need to support other environments can use it to conditionally load a Node.js built-in when it is run in Node.js, without having to deal with the resolution error that can be thrown by <code>import</code> in a non-Node.js environment or having to use dynamic <code>import()</code> which either turns the module into an asynchronous module, or turns a synchronous API into an asynchronous one.</p> <pre><code class="language-js mjs"><span class="hljs-keyword">if</span> (globalThis.<span class="hljs-property">process</span>?.<span class="hljs-property">getBuiltinModule</span>) { <span class="hljs-comment">// Run in Node.js, use the Node.js fs module.</span> <span class="hljs-keyword">const</span> fs = globalThis.<span class="hljs-property">process</span>.<span class="hljs-title function_">getBuiltinModule</span>(<span class="hljs-string">'fs'</span>); <span class="hljs-comment">// If `require()` is needed to load user-modules, use createRequire()</span> <span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = globalThis.<span class="hljs-property">process</span>.<span class="hljs-title function_">getBuiltinModule</span>(<span class="hljs-string">'module'</span>); <span class="hljs-keyword">const</span> <span class="hljs-built_in">require</span> = <span class="hljs-variable language_">module</span>.<span class="hljs-title function_">createRequire</span>(<span class="hljs-keyword">import</span>.<span class="hljs-property">meta</span>.<span class="hljs-property">url</span>); <span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">require</span>(<span class="hljs-string">'foo'</span>); }</code> <button class="copy-button">copy</button></pre> <p>If <code>id</code> specifies a built-in module available in the current Node.js process, <code>process.getBuiltinModule(id)</code> method returns the corresponding built-in module. If <code>id</code> does not correspond to any built-in module, <code>undefined</code> is returned.</p> <p><code>process.getBuiltinModule(id)</code> accepts built-in module IDs that are recognized by <a href="module.html#moduleisbuiltinmodulename"><code>module.isBuiltin(id)</code></a>. Some built-in modules must be loaded with the <code>node:</code> prefix, see <a href="modules.html#built-in-modules-with-mandatory-node-prefix">built-in modules with mandatory <code>node:</code> prefix</a>. The references returned by <code>process.getBuiltinModule(id)</code> always point to the built-in module corresponding to <code>id</code> even if users modify <a href="modules.html#requirecache"><code>require.cache</code></a> so that <code>require(id)</code> returns something else.</p> </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> <div class="api_metadata"> <span>Added in: v2.0.0</span> </div> <p>The <code>process.getegid()</code> method returns the numerical effective group identity of the Node.js process. (See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html"><code>getegid(2)</code></a>.)</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) { <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>); }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) { <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>); }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android).</p> </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> <div class="api_metadata"> <span>Added in: v2.0.0</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>The <code>process.geteuid()</code> method returns the numerical effective user identity of the process. (See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html"><code>geteuid(2)</code></a>.)</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) { <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>); }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) { <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>); }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android).</p> </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> <div class="api_metadata"> <span>Added in: v0.1.31</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>The <code>process.getgid()</code> method returns the numerical group identity of the process. (See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html"><code>getgid(2)</code></a>.)</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) { <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>); }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) { <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>); }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android).</p> </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> <div class="api_metadata"> <span>Added in: v0.9.4</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a></li> </ul> <p>The <code>process.getgroups()</code> method returns an array with the supplementary group IDs. POSIX leaves it unspecified if the effective group ID is included but Node.js ensures it always is.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) { <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> }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) { <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> }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android).</p> </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> <div class="api_metadata"> <span>Added in: v0.1.28</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> <p>The <code>process.getuid()</code> method returns the numeric user identity of the process. (See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html"><code>getuid(2)</code></a>.)</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) { <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>); }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) { <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>); }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android).</p> </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> <div class="api_metadata"> <span>Added in: v9.3.0</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>Indicates whether a callback has been set using <a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a>.</p> </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> <div class="api_metadata"> <span>Added in: v0.7.6</span> </div> <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> <ul> <li><code>time</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a> The result of a previous call to <code>process.hrtime()</code></li> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a></li> </ul> <p>This is the legacy version of <a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a> before <code>bigint</code> was introduced in JavaScript.</p> <p>The <code>process.hrtime()</code> method returns the current high-resolution real time in a <code>[seconds, nanoseconds]</code> tuple <code>Array</code>, where <code>nanoseconds</code> is the remaining part of the real time that can't be represented in second precision.</p> <p><code>time</code> is an optional parameter that must be the result of a previous <code>process.hrtime()</code> call to diff with the current time. If the parameter passed in is not a tuple <code>Array</code>, a <code>TypeError</code> will be thrown. Passing in a user-defined array instead of the result of a previous call to <code>process.hrtime()</code> will lead to undefined behavior.</p> <p>These times are relative to an arbitrary time in the past, and not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals:</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>; <span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>(); <span class="hljs-comment">// [ 1800216, 25 ]</span> <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time); <span class="hljs-comment">// [ 1, 552 ]</span> <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>); <span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span> }, <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>); <span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>; <span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>(); <span class="hljs-comment">// [ 1800216, 25 ]</span> <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time); <span class="hljs-comment">// [ 1, 552 ]</span> <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>); <span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span> }, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v10.7.0</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a></li> </ul> <p>The <code>bigint</code> version of the <a href="#processhrtimetime"><code>process.hrtime()</code></a> method returning the current high-resolution real time in nanoseconds as a <code>bigint</code>.</p> <p>Unlike <a href="#processhrtimetime"><code>process.hrtime()</code></a>, it does not support an additional <code>time</code> argument since the difference can just be computed directly by subtraction of the two <code>bigint</code>s.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>(); <span class="hljs-comment">// 191051479007711n</span> <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>(); <span class="hljs-comment">// 191052633396993n</span> <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>); <span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span> }, <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>); <span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>(); <span class="hljs-comment">// 191051479007711n</span> <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>(); <span class="hljs-comment">// 191052633396993n</span> <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>); <span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span> }, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.9.4</span> </div> <ul> <li><code>user</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The user name or numeric identifier.</li> <li><code>extraGroup</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A group name or numeric identifier.</li> </ul> <p>The <code>process.initgroups()</code> method reads the <code>/etc/group</code> file and initializes the group access list, using all groups of which the user is a member. This is a privileged operation that requires that the Node.js process either have <code>root</code> access or the <code>CAP_SETGID</code> capability.</p> <p>Use care when dropping privileges:</p> <pre class="with-66-chars"><input class="js-flavor-toggle" 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>; <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> <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> <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> <span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>); <span class="hljs-comment">// drop root gid</span> <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>); <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> <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> <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> <span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>); <span class="hljs-comment">// drop root gid</span> <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> <p>This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <span>Added in: v0.0.6</span> </div> <ul> <li><code>pid</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A process ID</li> <li><code>signal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The signal to send, either as a string or number. <strong>Default:</strong> <code>'SIGTERM'</code>.</li> </ul> <p>The <code>process.kill()</code> method sends the <code>signal</code> to the process identified by <code>pid</code>.</p> <p>Signal names are strings such as <code>'SIGINT'</code> or <code>'SIGHUP'</code>. See <a href="#signal-events">Signal Events</a> and <a href="http://man7.org/linux/man-pages/man2/kill.2.html"><code>kill(2)</code></a> for more information.</p> <p>This method will throw an error if the target <code>pid</code> does not exist. As a special case, a signal of <code>0</code> can be used to test for the existence of a process. Windows platforms will throw an error if the <code>pid</code> is used to kill a process group.</p> <p>Even though the name of this function is <code>process.kill()</code>, it is really just a signal sender, like the <code>kill</code> system call. The signal sent may do something other than kill the target process.</p> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>); }); <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>); process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>); }, <span class="hljs-number">100</span>); <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>); process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>); }); <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>); process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>); }, <span class="hljs-number">100</span>); process.<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> <p>When <code>SIGUSR1</code> is received by a Node.js process, Node.js will start the debugger. See <a href="#signal-events">Signal Events</a>.</p> </section><section><h3><code>process.loadEnvFile(path)</code><span><a class="mark" href="#processloadenvfilepath" id="processloadenvfilepath">#</a></span><a aria-hidden="true" class="legacy" id="process_process_loadenvfile_path"></a></h3> <div class="api_metadata"> <span>Added in: v20.12.0</span> </div> <p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a>.1 - Active development</div><p></p> <ul> <li><code>path</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="url.html#the-whatwg-url-api" class="type"><URL></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a>. <strong>Default:</strong> <code>'./.env'</code></li> </ul> <p>Loads the <code>.env</code> file into <code>process.env</code>. Usage of <code>NODE_OPTIONS</code> in the <code>.env</code> file will not have any effect on Node.js.</p> <pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" aria-label="Show modern ES modules syntax"><code class="language-js cjs"><span class="hljs-keyword">const</span> { loadEnvFile } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>); <span class="hljs-title function_">loadEnvFile</span>();</code><code class="language-js mjs"><span class="hljs-keyword">import</span> { loadEnvFile } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>; <span class="hljs-title function_">loadEnvFile</span>();</code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.1.17</span><span>Deprecated since: v14.0.0</span> </div> <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> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>The <code>process.mainModule</code> property provides an alternative way of retrieving <a href="modules.html#accessing-the-main-module"><code>require.main</code></a>. The difference is that if the main module changes at runtime, <a href="modules.html#accessing-the-main-module"><code>require.main</code></a> may still refer to the original main module in modules that were required before the change occurred. Generally, it's safe to assume that the two refer to the same module.</p> <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 is no entry script.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.9.0, v12.17.0</td> <td><p>Added <code>arrayBuffers</code> to the returned object.</p></td></tr> <tr><td>v7.2.0</td> <td><p>Added <code>external</code> to the returned object.</p></td></tr> <tr><td>v0.1.16</td> <td><p><span>Added in: v0.1.16</span></p></td></tr> </tbody></table> </details> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> <ul> <li><code>rss</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> <li><code>heapTotal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> <li><code>heapUsed</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> <li><code>external</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> <li><code>arrayBuffers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> </li> </ul> <p>Returns an object describing the memory usage of the Node.js process measured in bytes.</p> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>()); <span class="hljs-comment">// Prints:</span> <span class="hljs-comment">// {</span> <span class="hljs-comment">// rss: 4935680,</span> <span class="hljs-comment">// heapTotal: 1826816,</span> <span class="hljs-comment">// heapUsed: 650472,</span> <span class="hljs-comment">// external: 49879,</span> <span class="hljs-comment">// arrayBuffers: 9386</span> <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>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>()); <span class="hljs-comment">// Prints:</span> <span class="hljs-comment">// {</span> <span class="hljs-comment">// rss: 4935680,</span> <span class="hljs-comment">// heapTotal: 1826816,</span> <span class="hljs-comment">// heapUsed: 650472,</span> <span class="hljs-comment">// external: 49879,</span> <span class="hljs-comment">// arrayBuffers: 9386</span> <span class="hljs-comment">// }</span></code><button class="copy-button">copy</button></pre> <ul> <li><code>heapTotal</code> and <code>heapUsed</code> refer to V8's memory usage.</li> <li><code>external</code> refers to the memory usage of C++ objects bound to JavaScript objects managed by V8.</li> <li><code>rss</code>, Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the process, including all C++ and JavaScript objects and code.</li> <li><code>arrayBuffers</code> refers to memory allocated for <code>ArrayBuffer</code>s and <code>SharedArrayBuffer</code>s, including all Node.js <a href="buffer.html"><code>Buffer</code></a>s. This is also included in the <code>external</code> value. When Node.js is used as an embedded library, this value may be <code>0</code> because allocations for <code>ArrayBuffer</code>s may not be tracked in that case.</li> </ul> <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 entire process, while the other fields will only refer to the current thread.</p> <p>The <code>process.memoryUsage()</code> method iterates over each page to gather information about memory usage which might be slow depending on the program memory allocations.</p> </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> <div class="api_metadata"> <span>Added in: v15.6.0, v14.18.0</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> <p>The <code>process.memoryUsage.rss()</code> method returns an integer representing the Resident Set Size (RSS) in bytes.</p> <p>The Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the process, including all C++ and JavaScript objects and code.</p> <p>This is the same value as the <code>rss</code> property provided by <code>process.memoryUsage()</code> but <code>process.memoryUsage.rss()</code> is faster.</p> <pre class="with-48-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>()); <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>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>()); <span class="hljs-comment">// 35655680</span></code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v20.18.0</td> <td><p>Changed stability to Legacy.</p></td></tr> <tr><td>v18.0.0</td> <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> <tr><td>v1.8.1</td> <td><p>Additional arguments after <code>callback</code> are now supported.</p></td></tr> <tr><td>v0.1.26</td> <td><p><span>Added in: v0.1.26</span></p></td></tr> </tbody></table> </details> </div> <p></p><div class="api_stability api_stability_3"><a href="documentation.html#stability-index">Stability: 3</a> - Legacy: Use <a href="globals.html#queuemicrotaskcallback"><code>queueMicrotask()</code></a> instead.</div><p></p> <ul> <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li> <li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> Additional arguments to pass when invoking the <code>callback</code></li> </ul> <p><code>process.nextTick()</code> adds <code>callback</code> to the "next tick queue". This queue is fully drained after the current operation on the JavaScript stack runs to completion and before the event loop is allowed to continue. It's possible to create an infinite loop if one were to recursively call <code>process.nextTick()</code>. See the <a href="https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#understanding-processnexttick">Event Loop</a> guide for more background.</p> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>); <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-string">'nextTick callback'</span>); }); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>); <span class="hljs-comment">// Output:</span> <span class="hljs-comment">// start</span> <span class="hljs-comment">// scheduled</span> <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>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>); <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-string">'nextTick callback'</span>); }); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>); <span class="hljs-comment">// Output:</span> <span class="hljs-comment">// start</span> <span class="hljs-comment">// scheduled</span> <span class="hljs-comment">// nextTick callback</span></code><button class="copy-button">copy</button></pre> <p>This is important when developing APIs in order to give users the opportunity to assign event handlers <em>after</em> an object has been constructed but before any I/O has occurred:</p> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options); <span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>(); }); } <span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>(); thing.<span class="hljs-title function_">getReadyForStuff</span>(); <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>); <span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options); <span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> { <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>(); }); } <span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>(); thing.<span class="hljs-title function_">getReadyForStuff</span>(); <span class="hljs-comment">// thing.startDoingStuff() gets called now, not before.</span></code><button class="copy-button">copy</button></pre> <p>It is very important for APIs to be either 100% synchronous or 100% asynchronous. Consider this example:</p> <pre><code class="language-js"><span class="hljs-comment">// WARNING! DO NOT USE! BAD UNSAFE HAZARD!</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">maybeSync</span>(<span class="hljs-params">arg, cb</span>) { <span class="hljs-keyword">if</span> (arg) { <span class="hljs-title function_">cb</span>(); <span class="hljs-keyword">return</span>; } fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb); }</code> <button class="copy-button">copy</button></pre> <p>This API is hazardous because in the following case:</p> <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>; <span class="hljs-title function_">maybeSync</span>(maybeTrue, <span class="hljs-function">() =></span> { <span class="hljs-title function_">foo</span>(); }); <span class="hljs-title function_">bar</span>();</code> <button class="copy-button">copy</button></pre> <p>It is not clear whether <code>foo()</code> or <code>bar()</code> will be called first.</p> <p>The following approach is much better:</p> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) { <span class="hljs-keyword">if</span> (arg) { <span class="hljs-title function_">nextTick</span>(cb); <span class="hljs-keyword">return</span>; } fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb); }</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>); <span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) { <span class="hljs-keyword">if</span> (arg) { <span class="hljs-title function_">nextTick</span>(cb); <span class="hljs-keyword">return</span>; } fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb); }</code><button class="copy-button">copy</button></pre> <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> <p>The <a href="globals.html#queuemicrotaskcallback"><code>queueMicrotask()</code></a> API is an alternative to <code>process.nextTick()</code> that also defers execution of a function using the same microtask queue used to execute the then, catch, and finally handlers of resolved promises. Within Node.js, every time the "next tick queue" is drained, the microtask queue is drained immediately after.</p> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; <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>)); <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>)); <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>)); <span class="hljs-comment">// Output:</span> <span class="hljs-comment">// 1</span> <span class="hljs-comment">// 2</span> <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>); <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>)); <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>)); <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>)); <span class="hljs-comment">// Output:</span> <span class="hljs-comment">// 1</span> <span class="hljs-comment">// 2</span> <span class="hljs-comment">// 3</span></code><button class="copy-button">copy</button></pre> <p>For <em>most</em> userland use cases, the <code>queueMicrotask()</code> API provides a portable and reliable mechanism for deferring execution that works across multiple JavaScript platform environments and should be favored over <code>process.nextTick()</code>. In simple scenarios, <code>queueMicrotask()</code> can be a drop-in replacement for <code>process.nextTick()</code>.</p> <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>); <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-string">'microtask callback'</span>); }); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>); <span class="hljs-comment">// Output:</span> <span class="hljs-comment">// start</span> <span class="hljs-comment">// scheduled</span> <span class="hljs-comment">// microtask callback</span></code> <button class="copy-button">copy</button></pre> <p>One note-worthy difference between the two APIs is that <code>process.nextTick()</code> allows specifying additional values that will be passed as arguments to the deferred function when it is called. Achieving the same result with <code>queueMicrotask()</code> requires using either a closure or a bound function:</p> <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>) { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask'</span>, a + b); } <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>); <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>)); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>); <span class="hljs-comment">// Output:</span> <span class="hljs-comment">// start</span> <span class="hljs-comment">// scheduled</span> <span class="hljs-comment">// microtask 3</span></code> <button class="copy-button">copy</button></pre> <p>There are minor differences in the way errors raised from within the next tick queue and microtask queue are handled. Errors thrown within a queued microtask callback should be handled within the queued callback when possible. If they are not, the <code>process.on('uncaughtException')</code> event handler can be used to capture and handle the errors.</p> <p>When in doubt, unless the specific capabilities of <code>process.nextTick()</code> are needed, use <code>queueMicrotask()</code>.</p> </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> <div class="api_metadata"> <span>Added in: v0.8.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>The <code>process.noDeprecation</code> property indicates whether the <code>--no-deprecation</code> flag is set on the current Node.js process. See the documentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the <a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this flag's behavior.</p> </section><section><h3><code>process.permission</code><span><a class="mark" href="#processpermission" id="processpermission">#</a></span><a aria-hidden="true" class="legacy" id="process_process_permission"></a></h3> <div class="api_metadata"> <span>Added in: v20.0.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>This API is available through the <a href="cli.html#--experimental-permission"><code>--experimental-permission</code></a> flag.</p> <p><code>process.permission</code> is an object whose methods are used to manage permissions for the current process. Additional documentation is available in the <a href="permissions.html#permission-model">Permission Model</a>.</p> <h4><code>process.permission.has(scope[, reference])</code><span><a class="mark" href="#processpermissionhasscope-reference" id="processpermissionhasscope-reference">#</a></span><a aria-hidden="true" class="legacy" id="process_process_permission_has_scope_reference"></a></h4> <div class="api_metadata"> <span>Added in: v20.0.0</span> </div> <ul> <li><code>scope</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> <li><code>reference</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>Verifies that the process is able to access the given scope and reference. If no reference is provided, a global scope is assumed, for instance, <code>process.permission.has('fs.read')</code> will check if the process has ALL file system read permissions.</p> <p>The reference has a meaning based on the provided scope. For example, the reference when the scope is File System means files and folders.</p> <p>The available scopes are:</p> <ul> <li><code>fs</code> - All File System</li> <li><code>fs.read</code> - File System read operations</li> <li><code>fs.write</code> - File System write operations</li> <li><code>child</code> - Child process spawning operations</li> <li><code>worker</code> - Worker thread spawning operation</li> </ul> <pre><code class="language-js"><span class="hljs-comment">// Check if the process has permission to read the README file</span> process.<span class="hljs-property">permission</span>.<span class="hljs-title function_">has</span>(<span class="hljs-string">'fs.read'</span>, <span class="hljs-string">'./README.md'</span>); <span class="hljs-comment">// Check if the process has read permission operations</span> process.<span class="hljs-property">permission</span>.<span class="hljs-title function_">has</span>(<span class="hljs-string">'fs.read'</span>);</code> <button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.1.15</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> <p>The <code>process.pid</code> property returns the PID of the process.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <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>); <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> </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> <div class="api_metadata"> <span>Added in: v0.1.16</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.platform</code> property returns a string identifying the operating system platform for which the Node.js binary was compiled.</p> <p>Currently possible values are:</p> <ul> <li><code>'aix'</code></li> <li><code>'darwin'</code></li> <li><code>'freebsd'</code></li> <li><code>'linux'</code></li> <li><code>'openbsd'</code></li> <li><code>'sunos'</code></li> <li><code>'win32'</code></li> </ul> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <p>The value <code>'android'</code> may also be returned if the Node.js is built on the Android operating system. However, Android support in Node.js <a href="https://github.com/nodejs/node/blob/HEAD/BUILDING.md#android">is experimental</a>.</p> </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> <div class="api_metadata"> <span>Added in: v9.2.0, v8.10.0, v6.13.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> <p>The <code>process.ppid</code> property returns the PID of the parent of the current process.</p> <pre class="with-41-chars"><input class="js-flavor-toggle" 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>; <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>); <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> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v4.2.0</td> <td><p>The <code>lts</code> property is now supported.</p></td></tr> <tr><td>v3.0.0</td> <td><p><span>Added in: v3.0.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>The <code>process.release</code> property returns an <code>Object</code> containing metadata related to the current release, including URLs for the source tarball and headers-only tarball.</p> <p><code>process.release</code> contains the following properties:</p> <ul> <li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A value that will always be <code>'node'</code>.</li> <li><code>sourceUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> an absolute URL pointing to a <em><code>.tar.gz</code></em> file containing the source code of the current release.</li> <li><code>headersUrl</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> an absolute URL pointing to a <em><code>.tar.gz</code></em> file containing only the source header files for the current release. This file is significantly smaller than the full source file and can be used for compiling Node.js native add-ons.</li> <li><code>libUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> an absolute URL pointing to a <em><code>node.lib</code></em> file matching the architecture and version of the current release. This file is used for compiling Node.js native add-ons. <em>This property is only present on Windows builds of Node.js and will be missing on all other platforms.</em></li> <li><code>lts</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> a string label identifying the <a href="https://github.com/nodejs/Release">LTS</a> label for this release. This property only exists for LTS releases and is <code>undefined</code> for all other release types, including <em>Current</em> releases. Valid values include the LTS Release code names (including those that are no longer supported). <ul> <li><code>'Fermium'</code> for the 14.x LTS line beginning with 14.15.0.</li> <li><code>'Gallium'</code> for the 16.x LTS line beginning with 16.13.0.</li> <li><code>'Hydrogen'</code> for the 18.x LTS line beginning with 18.12.0. For 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> </ul> </li> </ul> <!-- eslint-skip --> <pre><code class="language-js">{ <span class="hljs-attr">name</span>: <span class="hljs-string">'node'</span>, <span class="hljs-attr">lts</span>: <span class="hljs-string">'Hydrogen'</span>, <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>, <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>, <span class="hljs-attr">libUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/win-x64/node.lib'</span> }</code> <button class="copy-button">copy</button></pre> <p>In custom builds from non-release versions of the source tree, only the <code>name</code> property may be present. The additional properties should not be relied upon to exist.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.8.0</td> <td><p><span>Added in: v11.8.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p><code>process.report</code> is an object whose methods are used to generate diagnostic reports for the current process. Additional documentation is available in the <a href="report.html">report documentation</a>.</p> <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> <div class="api_metadata"> <span>Added in: v13.12.0, v12.17.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>Write reports in a compact format, single-line JSON, more easily consumable by log processing systems than the default multi-line format designed for human consumption.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.12.0</td> <td><p><span>Added in: v11.12.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>Directory where the report is written. The default value is the empty string, indicating that reports are written to the current working directory of the Node.js process.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.12.0</td> <td><p><span>Added in: v11.12.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>Filename where the report is written. If set to the empty string, the output filename will be comprised of a timestamp, PID, and sequence number. The default value is the empty string.</p> <p>If the value of <code>process.report.filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>, the report is written to the stdout or stderr of the process respectively.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.8.0</td> <td><p><span>Added in: v11.8.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> A custom error used for reporting the JavaScript stack.</li> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>Returns a JavaScript Object representation of a diagnostic report for the running process. The report's JavaScript stack trace is taken from <code>err</code>, if present.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">import</span> util <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>; <span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>(); <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>); <span class="hljs-comment">// Similar to process.report.writeReport()</span> <span class="hljs-keyword">import</span> fs <span class="hljs-keyword">from</span> <span class="hljs-string">'node:fs'</span>; fs.<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>); <span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>); <span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>(); <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>); <span class="hljs-comment">// Similar to process.report.writeReport()</span> <span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>); fs.<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> <p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v15.0.0, v14.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.12.0</td> <td><p><span>Added in: v11.12.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>If <code>true</code>, a diagnostic report is generated on fatal errors, such as out of memory errors or failed C++ assertions.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.12.0</td> <td><p><span>Added in: v11.12.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>If <code>true</code>, a diagnostic report is generated when the process receives the signal specified by <code>process.report.signal</code>.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.12.0</td> <td><p><span>Added in: v11.12.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>If <code>true</code>, a diagnostic report is generated on uncaught exception.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.12.0</td> <td><p><span>Added in: v11.12.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The signal used to trigger the creation of a diagnostic report. Defaults to <code>'SIGUSR2'</code>.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; <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>); <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> <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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v13.12.0, v12.17.0</td> <td><p>This API is no longer experimental.</p></td></tr> <tr><td>v11.8.0</td> <td><p><span>Added in: v11.8.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li> <p><code>filename</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Name of the file where the report is written. This should be a relative path, that will be appended to the directory specified in <code>process.report.directory</code>, or the current working directory of the Node.js process, if unspecified.</p> </li> <li> <p><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> A custom error used for reporting the JavaScript stack.</p> </li> <li> <p>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Returns the filename of the generated report.</p> </li> </ul> <p>Writes a diagnostic report to a file. If <code>filename</code> is not provided, the default filename includes the date, time, PID, and a sequence number. The report's JavaScript stack trace is taken from <code>err</code>, if present.</p> <p>If the value of <code>filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>, the report is written to the stdout or stderr of the process respectively.</p> <pre class="with-43-chars"><input class="js-flavor-toggle" 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>; report.<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>); report.<span class="hljs-title function_">writeReport</span>();</code><button class="copy-button">copy</button></pre> <p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p> </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> <div class="api_metadata"> <span>Added in: v12.6.0</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> the resource usage for the current process. All of these values come from the <code>uv_getrusage</code> call which returns a <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t"><code>uv_rusage_t</code> struct</a>. <ul> <li><code>userCPUTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_utime</code> computed in microseconds. It is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().user</code></a>.</li> <li><code>systemCPUTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_stime</code> computed in microseconds. It is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().system</code></a>.</li> <li><code>maxRSS</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_maxrss</code> which is the maximum resident set size used in kilobytes.</li> <li><code>sharedMemorySize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_ixrss</code> but is not supported by any platform.</li> <li><code>unsharedDataSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_idrss</code> but is not supported by any platform.</li> <li><code>unsharedStackSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_isrss</code> but is not supported by any platform.</li> <li><code>minorPageFault</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_minflt</code> which is the number of minor page faults for the process, see <a href="https://en.wikipedia.org/wiki/Page_fault#Minor">this article for more details</a>.</li> <li><code>majorPageFault</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_majflt</code> which is the number of major page faults for the process, see <a href="https://en.wikipedia.org/wiki/Page_fault#Major">this article for more details</a>. This field is not supported on Windows.</li> <li><code>swappedOut</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nswap</code> but is not supported by any platform.</li> <li><code>fsRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_inblock</code> which is the number of times the file system had to perform input.</li> <li><code>fsWrite</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_oublock</code> which is the number of times the file system had to perform output.</li> <li><code>ipcSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_msgsnd</code> but is not supported by any platform.</li> <li><code>ipcReceived</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_msgrcv</code> but is not supported by any platform.</li> <li><code>signalsCount</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nsignals</code> but is not supported by any platform.</li> <li><code>voluntaryContextSwitches</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nvcsw</code> which is the number of times a CPU context switch resulted due to a process voluntarily giving up the processor before its time slice was completed (usually to await availability of a resource). This field is not supported on Windows.</li> <li><code>involuntaryContextSwitches</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nivcsw</code> which is the number of times a CPU context switch resulted due to a higher priority process becoming runnable or because the current process exceeded its time slice. This field is not supported on Windows.</li> </ul> </li> </ul> <pre class="with-50-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>()); <span class="hljs-comment">/* Will output: { userCPUTime: 82872, systemCPUTime: 4143, maxRSS: 33164, sharedMemorySize: 0, unsharedDataSize: 0, unsharedStackSize: 0, minorPageFault: 2469, majorPageFault: 0, swappedOut: 0, fsRead: 0, fsWrite: 8, ipcSent: 0, ipcReceived: 0, signalsCount: 0, voluntaryContextSwitches: 79, involuntaryContextSwitches: 1 } */</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>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>()); <span class="hljs-comment">/* Will output: { userCPUTime: 82872, systemCPUTime: 4143, maxRSS: 33164, sharedMemorySize: 0, unsharedDataSize: 0, unsharedStackSize: 0, minorPageFault: 2469, majorPageFault: 0, swappedOut: 0, fsRead: 0, fsWrite: 8, ipcSent: 0, ipcReceived: 0, signalsCount: 0, voluntaryContextSwitches: 79, involuntaryContextSwitches: 1 } */</span></code><button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.5.9</span> </div> <ul> <li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> <li><code>sendHandle</code> <a href="net.html#class-netserver" class="type"><net.Server></a> | <a href="net.html#class-netsocket" class="type"><net.Socket></a></li> <li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> used to parameterize the sending of certain types of handles.<code>options</code> supports the following properties: <ul> <li><code>keepOpen</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> A value that can be used when passing instances of <code>net.Socket</code>. When <code>true</code>, the socket is kept open in the sending process. <strong>Default:</strong> <code>false</code>.</li> </ul> </li> <li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>If Node.js is spawned with an IPC channel, the <code>process.send()</code> method can be used to send messages to the parent process. Messages will be received as a <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> <p>If Node.js was not spawned with an IPC channel, <code>process.send</code> will be <code>undefined</code>.</p> <p>The message goes through serialization and parsing. The resulting message might not be the same as what is originally sent.</p> </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> <div class="api_metadata"> <span>Added in: v2.0.0</span> </div> <ul> <li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A group name or ID</li> </ul> <p>The <code>process.setegid()</code> method sets the effective group identity of the process. (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 name string. If a group name is specified, this method blocks while resolving the associated a numeric ID.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> && process.<span class="hljs-property">setegid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> && process.<span class="hljs-property">setegid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <span>Added in: v2.0.0</span> </div> <ul> <li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A user name or ID</li> </ul> <p>The <code>process.seteuid()</code> method sets the effective user identity of the process. (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 string. If a username is specified, the method blocks while resolving the associated numeric ID.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> && process.<span class="hljs-property">seteuid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> && process.<span class="hljs-property">seteuid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <span>Added in: v0.1.31</span> </div> <ul> <li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The group name or ID</li> </ul> <p>The <code>process.setgid()</code> method sets the group identity of the process. (See <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 string. If a group name is specified, this method blocks while resolving the associated numeric ID.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> && process.<span class="hljs-property">setgid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> && process.<span class="hljs-property">setgid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <span>Added in: v0.9.4</span> </div> <ul> <li><code>groups</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a></li> </ul> <p>The <code>process.setgroups()</code> method sets the supplementary group IDs for the Node.js process. This is a privileged operation that requires the Node.js process to have <code>root</code> or the <code>CAP_SETGID</code> capability.</p> <p>The <code>groups</code> array can contain numeric group IDs, group names, or both.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> && process.<span class="hljs-property">setgroups</span>) { <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]); <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> } <span class="hljs-keyword">catch</span> (err) { <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>); } }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> && process.<span class="hljs-property">setgroups</span>) { <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]); <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> } <span class="hljs-keyword">catch</span> (err) { <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>); } }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <span>Added in: v0.1.28</span> </div> <ul> <li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.setuid(id)</code> method sets the user identity of the process. (See <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. If a username is specified, the method blocks while resolving the associated numeric ID.</p> <pre class="with-40-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> && process.<span class="hljs-property">setuid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</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>); <span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> && process.<span class="hljs-property">setuid</span>) { <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>); <span class="hljs-keyword">try</span> { process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>); <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>); } <span class="hljs-keyword">catch</span> (err) { <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>); } }</code><button class="copy-button">copy</button></pre> <p>This function is only available on POSIX platforms (i.e. not Windows or Android). This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p> </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> <div class="api_metadata"> <span>Added in: v16.6.0, v14.18.0</span> </div> <p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p> <ul> <li><code>val</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>This function enables or disables the <a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for stack traces.</p> <p>It provides same features as launching Node.js process with commandline options <code>--enable-source-maps</code>.</p> <p>Only source maps in JavaScript files that are loaded after source maps has been enabled will be parsed and loaded.</p> </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> <div class="api_metadata"> <span>Added in: v9.3.0</span> </div> <ul> <li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a></li> </ul> <p>The <code>process.setUncaughtExceptionCaptureCallback()</code> function sets a function that will be invoked when an uncaught exception occurs, which will receive the exception value itself as its first argument.</p> <p>If such a function is set, the <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event will not be emitted. If <code>--abort-on-uncaught-exception</code> was passed from the command line or set through <a href="v8.html#v8setflagsfromstringflags"><code>v8.setFlagsFromString()</code></a>, the process will not abort. Actions configured to take place on exceptions such as report generations will be affected too</p> <p>To unset the capture function, <code>process.setUncaughtExceptionCaptureCallback(null)</code> may be used. Calling this method with a non-<code>null</code> argument while another capture function is set will throw an error.</p> <p>Using this function is mutually exclusive with using the deprecated <a href="domain.html"><code>domain</code></a> built-in module.</p> </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> <div class="api_metadata"> <span>Added in: v20.7.0</span> </div> <p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>The <code>process.sourceMapsEnabled</code> property returns whether the <a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for stack traces is enabled.</p> </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> <ul> <li><a href="stream.html#stream" class="type"><Stream></a></li> </ul> <p>The <code>process.stderr</code> property returns a stream connected to <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> stream) unless fd <code>2</code> refers to a file, in which case it is a <a href="stream.html#writable-streams">Writable</a> stream.</p> <p><code>process.stderr</code> differs from other Node.js streams in important ways. See <a href="#a-note-on-process-io">note on process I/O</a> for more information.</p> <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> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> </ul> <p>This property refers to the value of underlying file descriptor of <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, this field does not exist.</p> </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> <ul> <li><a href="stream.html#stream" class="type"><Stream></a></li> </ul> <p>The <code>process.stdin</code> property returns a stream connected to <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> stream) unless fd <code>0</code> refers to a file, in which case it is a <a href="stream.html#readable-streams">Readable</a> stream.</p> <p>For details of how to read from <code>stdin</code> see <a href="stream.html#readablereadsize"><code>readable.read()</code></a>.</p> <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 is compatible with scripts written for Node.js prior to v0.10. For more information see <a href="stream.html#compatibility-with-older-nodejs-versions">Stream compatibility</a>.</p> <p>In "old" streams mode the <code>stdin</code> stream is paused by default, so one must call <code>process.stdin.resume()</code> to read from it. Note also that calling <code>process.stdin.resume()</code> itself would switch stream to "old" mode.</p> <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> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> </ul> <p>This property refers to the value of underlying file descriptor of <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, this field does not exist.</p> </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> <ul> <li><a href="stream.html#stream" class="type"><Stream></a></li> </ul> <p>The <code>process.stdout</code> property returns a stream connected to <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> stream) unless fd <code>1</code> refers to a file, in which case it is a <a href="stream.html#writable-streams">Writable</a> stream.</p> <p>For example, to copy <code>process.stdin</code> to <code>process.stdout</code>:</p> <pre class="with-50-chars"><input class="js-flavor-toggle" 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>; stdin.<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>); stdin.<span class="hljs-title function_">pipe</span>(stdout);</code><button class="copy-button">copy</button></pre> <p><code>process.stdout</code> differs from other Node.js streams in important ways. See <a href="#a-note-on-process-io">note on process I/O</a> for more information.</p> <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> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> </ul> <p>This property refers to the value of underlying file descriptor of <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, this field does not exist.</p> <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> <p><code>process.stdout</code> and <code>process.stderr</code> differ from other Node.js streams in important ways:</p> <ol> <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>, respectively.</li> <li>Writes may be synchronous depending on what the stream is connected to and whether the system is Windows or POSIX: <ul> <li>Files: <em>synchronous</em> on Windows and POSIX</li> <li>TTYs (Terminals): <em>asynchronous</em> on Windows, <em>synchronous</em> on POSIX</li> <li>Pipes (and sockets): <em>synchronous</em> on Windows, <em>asynchronous</em> on POSIX</li> </ul> </li> </ol> <p>These behaviors are partly for historical reasons, as changing them would create backward incompatibility, but they are also expected by some users.</p> <p>Synchronous writes avoid problems such as output written with <code>console.log()</code> or <code>console.error()</code> being unexpectedly interleaved, or not written at all if <code>process.exit()</code> is called before an asynchronous write completes. See <a href="#processexitcode"><code>process.exit()</code></a> for more information.</p> <p><em><strong>Warning</strong></em>: Synchronous writes block the event loop until the write has completed. This can be near instantaneous in the case of output to a file, but under high system load, pipes that are not being read at the receiving end, or with slow terminals or file systems, it's possible for the event loop to be blocked often enough and long enough to have severe negative performance impacts. This may not be a problem when writing to an interactive terminal session, but consider this particularly careful when doing production logging to the process output streams.</p> <p>To check if a stream is connected to a <a href="tty.html#tty">TTY</a> context, check the <code>isTTY</code> property.</p> <p>For instance:</p> <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> true <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> false <span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span></span> true <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> false</code> <button class="copy-button">copy</button></pre> <p>See the <a href="tty.html#tty">TTY</a> documentation for more information.</p> </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> <div class="api_metadata"> <span>Added in: v0.9.12</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>The initial value of <code>process.throwDeprecation</code> indicates whether the <code>--throw-deprecation</code> flag is set on the current Node.js process. <code>process.throwDeprecation</code> is mutable, so whether or not deprecation warnings result in errors may be altered at runtime. See the documentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the <a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information.</p> <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> true <span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"process.throwDeprecation"</span></span> undefined <span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span> <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> undefined <span class="hljs-meta prompt_">> </span><span class="language-bash">(node:26598) DeprecationWarning: <span class="hljs-built_in">test</span></span> <span class="hljs-meta prompt_">> </span><span class="language-bash">process.throwDeprecation = <span class="hljs-literal">true</span>;</span> true <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> Thrown: [DeprecationWarning: test] { name: 'DeprecationWarning' }</code> <button class="copy-button">copy</button></pre> </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> <div class="api_metadata"> <span>Added in: v0.1.104</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.title</code> property returns the current process title (i.e. returns the current value of <code>ps</code>). Assigning a new value to <code>process.title</code> modifies the current value of <code>ps</code>.</p> <p>When a new value is assigned, different platforms will impose different maximum length restrictions on the title. Usually such restrictions are quite limited. For instance, on Linux and macOS, <code>process.title</code> is limited to the size of the binary name plus the length of the command-line arguments because setting the <code>process.title</code> overwrites the <code>argv</code> memory of the process. Node.js v0.8 allowed for longer process title strings by also overwriting the <code>environ</code> memory but that was potentially insecure and confusing in some (rather obscure) cases.</p> <p>Assigning a value to <code>process.title</code> might not result in an accurate label within process manager applications such as macOS Activity Monitor or Windows Services Manager.</p> </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> <div class="api_metadata"> <span>Added in: v0.8.0</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> </ul> <p>The <code>process.traceDeprecation</code> property indicates whether the <code>--trace-deprecation</code> flag is set on the current Node.js process. See the documentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the <a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this flag's behavior.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v14.0.0, v12.19.0</td> <td><p>Calling <code>process.umask()</code> with no arguments is deprecated.</p></td></tr> <tr><td>v0.1.19</td> <td><p><span>Added in: v0.1.19</span></p></td></tr> </tbody></table> </details> </div> <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 the process-wide umask to be written twice. This introduces a race condition between threads, and is a potential security vulnerability. There is no safe, cross-platform alternative API.</div><p></p> <p><code>process.umask()</code> returns the Node.js process's file mode creation mask. Child processes inherit the mask from the parent process.</p> </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> <div class="api_metadata"> <span>Added in: v0.1.19</span> </div> <ul> <li><code>mask</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li> </ul> <p><code>process.umask(mask)</code> sets the Node.js process's file mode creation mask. Child processes inherit the mask from the parent process. Returns the previous mask.</p> <pre class="with-42-chars"><input class="js-flavor-toggle" 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>; <span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>; <span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>( <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>, );</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>); <span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>; <span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>( <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>, );</code><button class="copy-button">copy</button></pre> <p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, <code>process.umask(mask)</code> will throw an exception.</p> </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> <div class="api_metadata"> <span>Added in: v0.5.0</span> </div> <ul> <li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> </ul> <p>The <code>process.uptime()</code> method returns the number of seconds the current Node.js process has been running.</p> <p>The return value includes fractions of a second. Use <code>Math.floor()</code> to get whole seconds.</p> </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> <div class="api_metadata"> <span>Added in: v0.1.3</span> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> </ul> <p>The <code>process.version</code> property contains the Node.js version string.</p> <pre class="with-44-chars"><input class="js-flavor-toggle" 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>; <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>); <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>); <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>); <span class="hljs-comment">// Version: v14.8.0</span></code><button class="copy-button">copy</button></pre> <p>To get the version string without the prepended <em>v</em>, use <code>process.versions.node</code>.</p> </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> <div class="api_metadata"> <details class="changelog"><summary>History</summary> <table> <tbody><tr><th>Version</th><th>Changes</th></tr> <tr><td>v9.0.0</td> <td><p>The <code>v8</code> property now includes a Node.js specific suffix.</p></td></tr> <tr><td>v4.2.0</td> <td><p>The <code>icu</code> property is now supported.</p></td></tr> <tr><td>v0.2.0</td> <td><p><span>Added in: v0.2.0</span></p></td></tr> </tbody></table> </details> </div> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> </ul> <p>The <code>process.versions</code> property returns an object listing the version strings of Node.js and its dependencies. <code>process.versions.modules</code> indicates the current ABI version, which is increased whenever a C++ API changes. Node.js will refuse to load modules that were compiled against a different module ABI version.</p> <pre class="with-45-chars"><input class="js-flavor-toggle" 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>; <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>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(versions);</code><button class="copy-button">copy</button></pre> <p>Will generate an object similar to:</p> <pre><code class="language-console">{ node: '23.0.0', acorn: '8.11.3', ada: '2.7.8', ares: '1.28.1', base64: '0.5.2', brotli: '1.1.0', cjs_module_lexer: '1.2.2', cldr: '45.0', icu: '75.1', llhttp: '9.2.1', modules: '127', napi: '9', nghttp2: '1.61.0', nghttp3: '0.7.0', ngtcp2: '1.3.0', openssl: '3.0.13+quic', simdjson: '3.8.0', simdutf: '5.2.4', tz: '2024a', undici: '6.13.0', unicode: '15.1', uv: '1.48.0', uvwasi: '0.0.20', v8: '12.4.254.14-node.11', zlib: '1.3.0.1-motley-7d77fb7' }</code> <button class="copy-button">copy</button></pre> </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> <p>Node.js will normally exit with a <code>0</code> status code when no more async operations are pending. The following status codes are used in other cases:</p> <ul> <li><code>1</code> <strong>Uncaught Fatal Exception</strong>: There was an uncaught exception, and it was not handled by a domain or an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event handler.</li> <li><code>2</code>: Unused (reserved by Bash for builtin misuse)</li> <li><code>3</code> <strong>Internal JavaScript Parse Error</strong>: The JavaScript source code internal in the Node.js bootstrapping process caused a parse error. This is extremely rare, and generally can only happen during development of Node.js itself.</li> <li><code>4</code> <strong>Internal JavaScript Evaluation Failure</strong>: The JavaScript source code internal in the Node.js bootstrapping process failed to return a function value when evaluated. This is extremely rare, and generally can only happen during development of Node.js itself.</li> <li><code>5</code> <strong>Fatal Error</strong>: There was a fatal unrecoverable error in V8. Typically a message will be printed to stderr with the prefix <code>FATAL ERROR</code>.</li> <li><code>6</code> <strong>Non-function Internal Exception Handler</strong>: There was an uncaught exception, but the internal fatal exception handler function was somehow set to a non-function, and could not be called.</li> <li><code>7</code> <strong>Internal Exception Handler Run-Time Failure</strong>: There was an uncaught exception, and the internal fatal exception handler function itself threw an error while attempting to handle it. This can happen, for example, if an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> or <code>domain.on('error')</code> handler throws an error.</li> <li><code>8</code>: Unused. In previous versions of Node.js, exit code 8 sometimes indicated an uncaught exception.</li> <li><code>9</code> <strong>Invalid Argument</strong>: Either an unknown option was specified, or an option requiring a value was provided without a value.</li> <li><code>10</code> <strong>Internal JavaScript Run-Time Failure</strong>: The JavaScript source code internal in the Node.js bootstrapping process threw an error when the bootstrapping function was called. This is extremely rare, and generally can only happen during development of Node.js itself.</li> <li><code>12</code> <strong>Invalid Debug Argument</strong>: The <code>--inspect</code> and/or <code>--inspect-brk</code> options were set, but the port number chosen was invalid or unavailable.</li> <li><code>13</code> <strong>Unfinished Top-Level Await</strong>: <code>await</code> was used outside of a function in the top-level code, but the passed <code>Promise</code> never resolved.</li> <li><code>14</code> <strong>Snapshot Failure</strong>: Node.js was started to build a V8 startup snapshot and it failed because certain requirements of the state of the application were not met.</li> <li><code>>128</code> <strong>Signal Exits</strong>: If Node.js receives a fatal signal such as <code>SIGKILL</code> or <code>SIGHUP</code>, then its exit code will be <code>128</code> plus the value of the signal code. This is a standard POSIX practice, since exit codes are defined to be 7-bit integers, and signal exits set the high-order bit, and then contain the value of the signal code. For example, signal <code>SIGABRT</code> has value <code>6</code>, so the expected exit code will be <code>128</code> + <code>6</code>, or <code>134</code>.</li> </ul></section> <!-- API END --> </div> </div> </div> </body> </html>