1 declare module 'process' {
2 import * as tty from 'node:tty';
3 import { Worker } from 'node:worker_threads';
5 var process: NodeJS.Process;
7 // this namespace merge is here because these are specifically used
8 // as the type for process.stdin, process.stdout, and process.stderr.
9 // they can't live in tty.d.ts because we need to disambiguate the imported name.
10 interface ReadStream extends tty.ReadStream {}
11 interface WriteStream extends tty.WriteStream {}
12 interface MemoryUsageFn {
14 * The `process.memoryUsage()` method iterate over each page to gather informations about memory
15 * usage which can be slow depending on the program memory allocations.
19 * method returns an integer representing the Resident Set Size (RSS) in bytes.
23 interface MemoryUsage {
34 interface ProcessRelease {
36 sourceUrl?: string | undefined;
37 headersUrl?: string | undefined;
38 libUrl?: string | undefined;
39 lts?: string | undefined;
41 interface ProcessVersions extends Dict<string> {
51 type Platform = 'aix' | 'android' | 'darwin' | 'freebsd' | 'haiku' | 'linux' | 'openbsd' | 'sunos' | 'win32' | 'cygwin' | 'netbsd';
52 type Architecture = 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x64';
91 type UncaughtExceptionOrigin = 'uncaughtException' | 'unhandledRejection';
92 type MultipleResolveType = 'resolve' | 'reject';
93 type BeforeExitListener = (code: number) => void;
94 type DisconnectListener = () => void;
95 type ExitListener = (code: number) => void;
96 type RejectionHandledListener = (promise: Promise<unknown>) => void;
97 type UncaughtExceptionListener = (error: Error, origin: UncaughtExceptionOrigin) => void;
99 * Most of the time the unhandledRejection will be an Error, but this should not be relied upon
100 * as *anything* can be thrown/rejected, it is therefore unsafe to assume the the value is an Error.
102 type UnhandledRejectionListener = (reason: unknown, promise: Promise<unknown>) => void;
103 type WarningListener = (warning: Error) => void;
104 type MessageListener = (message: unknown, sendHandle: unknown) => void;
105 type SignalsListener = (signal: Signals) => void;
106 type MultipleResolveListener = (type: MultipleResolveType, promise: Promise<unknown>, value: unknown) => void;
107 type WorkerListener = (worker: Worker) => void;
108 interface Socket extends ReadWriteStream {
109 isTTY?: true | undefined;
111 // Alias for compatibility
112 interface ProcessEnv extends Dict<string> {
114 * Can be used to change the default timezone at runtime
119 (time?: [number, number]): [number, number];
122 interface ProcessReport {
124 * Directory where the report is written.
125 * working directory of the Node.js process.
126 * @default '' indicating that reports are written to the current
130 * Filename where the report is written.
131 * The default value is the empty string.
132 * @default '' the output filename will be comprised of a timestamp,
133 * PID, and sequence number.
137 * Returns a JSON-formatted diagnostic report for the running process.
138 * The report's JavaScript stack trace is taken from err, if present.
140 getReport(err?: Error): string;
142 * If true, a diagnostic report is generated on fatal errors,
143 * such as out of memory errors or failed C++ assertions.
146 reportOnFatalError: boolean;
148 * If true, a diagnostic report is generated when the process
149 * receives the signal specified by process.report.signal.
152 reportOnSignal: boolean;
154 * If true, a diagnostic report is generated on uncaught exception.
157 reportOnUncaughtException: boolean;
159 * The signal used to trigger the creation of a diagnostic report.
164 * Writes a diagnostic report to a file. If filename is not provided, the default filename
165 * includes the date, time, PID, and a sequence number.
166 * The report's JavaScript stack trace is taken from err, if present.
168 * @param fileName Name of the file where the report is written.
169 * This should be a relative path, that will be appended to the directory specified in
170 * `process.report.directory`, or the current working directory of the Node.js process,
172 * @param error A custom error used for reporting the JavaScript stack.
173 * @return Filename of the generated report.
175 writeReport(fileName?: string): string;
176 writeReport(error?: Error): string;
177 writeReport(fileName?: string, err?: Error): string;
179 interface ResourceUsage {
182 involuntaryContextSwitches: number;
185 majorPageFault: number;
187 minorPageFault: number;
188 sharedMemorySize: number;
189 signalsCount: number;
191 systemCPUTime: number;
192 unsharedDataSize: number;
193 unsharedStackSize: number;
195 voluntaryContextSwitches: number;
197 interface EmitWarningOptions {
199 * When `warning` is a `string`, `type` is the name to use for the _type_ of warning being emitted.
203 type?: string | undefined;
205 * A unique identifier for the warning instance being emitted.
207 code?: string | undefined;
209 * When `warning` is a `string`, `ctor` is an optional function used to limit the generated stack trace.
211 * @default process.emitWarning
213 ctor?: Function | undefined;
215 * Additional text to include with the error.
217 detail?: string | undefined;
219 interface ProcessConfig {
220 readonly target_defaults: {
221 readonly cflags: any[];
222 readonly default_configuration: string;
223 readonly defines: string[];
224 readonly include_dirs: string[];
225 readonly libraries: string[];
227 readonly variables: {
228 readonly clang: number;
229 readonly host_arch: string;
230 readonly node_install_npm: boolean;
231 readonly node_install_waf: boolean;
232 readonly node_prefix: string;
233 readonly node_shared_openssl: boolean;
234 readonly node_shared_v8: boolean;
235 readonly node_shared_zlib: boolean;
236 readonly node_use_dtrace: boolean;
237 readonly node_use_etw: boolean;
238 readonly node_use_openssl: boolean;
239 readonly target_arch: string;
240 readonly v8_no_strict_aliasing: number;
241 readonly v8_use_snapshot: boolean;
242 readonly visibility: string;
245 interface Process extends EventEmitter {
247 * The `process.stdout` property returns a stream connected to`stdout` (fd `1`). It is a `net.Socket` (which is a `Duplex` stream) unless fd `1` refers to a file, in which case it is
248 * a `Writable` stream.
250 * For example, to copy `process.stdin` to `process.stdout`:
253 * import { stdin, stdout } from 'process';
255 * stdin.pipe(stdout);
258 * `process.stdout` differs from other Node.js streams in important ways. See `note on process I/O` for more information.
260 stdout: WriteStream & {
264 * The `process.stderr` property returns a stream connected to`stderr` (fd `2`). It is a `net.Socket` (which is a `Duplex` stream) unless fd `2` refers to a file, in which case it is
265 * a `Writable` stream.
267 * `process.stderr` differs from other Node.js streams in important ways. See `note on process I/O` for more information.
269 stderr: WriteStream & {
273 * The `process.stdin` property returns a stream connected to`stdin` (fd `0`). It is a `net.Socket` (which is a `Duplex` stream) unless fd `0` refers to a file, in which case it is
274 * a `Readable` stream.
276 * For details of how to read from `stdin` see `readable.read()`.
278 * As a `Duplex` stream, `process.stdin` can also be used in "old" mode that
279 * is compatible with scripts written for Node.js prior to v0.10\.
280 * For more information see `Stream compatibility`.
282 * In "old" streams mode the `stdin` stream is paused by default, so one
283 * must call `process.stdin.resume()` to read from it. Note also that calling`process.stdin.resume()` itself would switch stream to "old" mode.
285 stdin: ReadStream & {
290 * The `process.argv` property returns an array containing the command-line
291 * arguments passed when the Node.js process was launched. The first element will
292 * be {@link execPath}. See `process.argv0` if access to the original value
293 * of `argv[0]` is needed. The second element will be the path to the JavaScript
294 * file being executed. The remaining elements will be any additional command-line
297 * For example, assuming the following script for `process-args.js`:
300 * import { argv } from 'process';
302 * // print process.argv
303 * argv.forEach((val, index) => {
304 * console.log(`${index}: ${val}`);
308 * Launching the Node.js process as:
311 * $ node process-args.js one two=three four
314 * Would generate the output:
317 * 0: /usr/local/bin/node
318 * 1: /Users/mjr/work/node/process-args.js
327 * The `process.argv0` property stores a read-only copy of the original value of`argv[0]` passed when Node.js starts.
330 * $ bash -c 'exec -a customArgv0 ./node'
332 * '/Volumes/code/external/node/out/Release/node'
340 * The `process.execArgv` property returns the set of Node.js-specific command-line
341 * options passed when the Node.js process was launched. These options do not
342 * appear in the array returned by the {@link argv} property, and do not
343 * include the Node.js executable, the name of the script, or any options following
344 * the script name. These options are useful in order to spawn child processes with
345 * the same execution environment as the parent.
348 * $ node --harmony script.js --version
351 * Results in `process.execArgv`:
357 * And `process.argv`:
360 * ['/usr/local/bin/node', 'script.js', '--version']
363 * Refer to `Worker constructor` for the detailed behavior of worker
364 * threads with this property.
369 * The `process.execPath` property returns the absolute pathname of the executable
370 * that started the Node.js process. Symbolic links, if any, are resolved.
373 * '/usr/local/bin/node'
379 * The `process.abort()` method causes the Node.js process to exit immediately and
380 * generate a core file.
382 * This feature is not available in `Worker` threads.
387 * The `process.chdir()` method changes the current working directory of the
388 * Node.js process or throws an exception if doing so fails (for instance, if
389 * the specified `directory` does not exist).
392 * import { chdir, cwd } from 'process';
394 * console.log(`Starting directory: ${cwd()}`);
397 * console.log(`New directory: ${cwd()}`);
399 * console.error(`chdir: ${err}`);
403 * This feature is not available in `Worker` threads.
406 chdir(directory: string): void;
408 * The `process.cwd()` method returns the current working directory of the Node.js
412 * import { cwd } from 'process';
414 * console.log(`Current directory: ${cwd()}`);
420 * The port used by the Node.js debugger when enabled.
423 * import process from 'process';
425 * process.debugPort = 5858;
431 * The `process.emitWarning()` method can be used to emit custom or application
432 * specific process warnings. These can be listened for by adding a handler to the `'warning'` event.
435 * import { emitWarning } from 'process';
437 * // Emit a warning with a code and additional detail.
438 * emitWarning('Something happened!', {
439 * code: 'MY_WARNING',
440 * detail: 'This is some additional information'
443 * // (node:56338) [MY_WARNING] Warning: Something happened!
444 * // This is some additional information
447 * In this example, an `Error` object is generated internally by`process.emitWarning()` and passed through to the `'warning'` handler.
450 * import process from 'process';
452 * process.on('warning', (warning) => {
453 * console.warn(warning.name); // 'Warning'
454 * console.warn(warning.message); // 'Something happened!'
455 * console.warn(warning.code); // 'MY_WARNING'
456 * console.warn(warning.stack); // Stack trace
457 * console.warn(warning.detail); // 'This is some additional information'
461 * If `warning` is passed as an `Error` object, the `options` argument is ignored.
463 * @param warning The warning to emit.
465 emitWarning(warning: string | Error, ctor?: Function): void;
466 emitWarning(warning: string | Error, type?: string, ctor?: Function): void;
467 emitWarning(warning: string | Error, type?: string, code?: string, ctor?: Function): void;
468 emitWarning(warning: string | Error, options?: EmitWarningOptions): void;
470 * The `process.env` property returns an object containing the user environment.
471 * See [`environ(7)`](http://man7.org/linux/man-pages/man7/environ.7.html).
473 * An example of this object looks like:
477 * TERM: 'xterm-256color',
478 * SHELL: '/usr/local/bin/bash',
480 * PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
481 * PWD: '/Users/maciej',
484 * HOME: '/Users/maciej',
486 * _: '/usr/local/bin/node'
490 * It is possible to modify this object, but such modifications will not be
491 * reflected outside the Node.js process, or (unless explicitly requested)
492 * to other `Worker` threads.
493 * In other words, the following example would not work:
496 * $ node -e 'process.env.foo = "bar"' && echo $foo
499 * While the following will:
502 * import { env } from 'process';
505 * console.log(env.foo);
508 * Assigning a property on `process.env` will implicitly convert the value
509 * to a string. **This behavior is deprecated.** Future versions of Node.js may
510 * throw an error when the value is not a string, number, or boolean.
513 * import { env } from 'process';
516 * console.log(env.test);
518 * env.test = undefined;
519 * console.log(env.test);
523 * Use `delete` to delete a property from `process.env`.
526 * import { env } from 'process';
530 * console.log(env.TEST);
534 * On Windows operating systems, environment variables are case-insensitive.
537 * import { env } from 'process';
540 * console.log(env.test);
544 * Unless explicitly specified when creating a `Worker` instance,
545 * each `Worker` thread has its own copy of `process.env`, based on its
546 * parent thread’s `process.env`, or whatever was specified as the `env` option
547 * to the `Worker` constructor. Changes to `process.env` will not be visible
548 * across `Worker` threads, and only the main thread can make changes that
549 * are visible to the operating system or to native add-ons.
554 * The `process.exit()` method instructs Node.js to terminate the process
555 * synchronously with an exit status of `code`. If `code` is omitted, exit uses
556 * either the 'success' code `0` or the value of `process.exitCode` if it has been
557 * set. Node.js will not terminate until all the `'exit'` event listeners are
560 * To exit with a 'failure' code:
563 * import { exit } from 'process';
568 * The shell that executed Node.js should see the exit code as `1`.
570 * Calling `process.exit()` will force the process to exit as quickly as possible
571 * even if there are still asynchronous operations pending that have not yet
572 * completed fully, including I/O operations to `process.stdout` and`process.stderr`.
574 * In most situations, it is not actually necessary to call `process.exit()`explicitly. The Node.js process will exit on its own _if there is no additional_
575 * _work pending_ in the event loop. The `process.exitCode` property can be set to
576 * tell the process which exit code to use when the process exits gracefully.
578 * For instance, the following example illustrates a _misuse_ of the`process.exit()` method that could lead to data printed to stdout being
579 * truncated and lost:
582 * import { exit } from 'process';
584 * // This is an example of what *not* to do:
585 * if (someConditionNotMet()) {
586 * printUsageToStdout();
591 * The reason this is problematic is because writes to `process.stdout` in Node.js
592 * are sometimes _asynchronous_ and may occur over multiple ticks of the Node.js
593 * event loop. Calling `process.exit()`, however, forces the process to exit_before_ those additional writes to `stdout` can be performed.
595 * Rather than calling `process.exit()` directly, the code _should_ set the`process.exitCode` and allow the process to exit naturally by avoiding
596 * scheduling any additional work for the event loop:
599 * import process from 'process';
601 * // How to properly set the exit code while letting
602 * // the process exit gracefully.
603 * if (someConditionNotMet()) {
604 * printUsageToStdout();
605 * process.exitCode = 1;
609 * If it is necessary to terminate the Node.js process due to an error condition,
610 * throwing an _uncaught_ error and allowing the process to terminate accordingly
611 * is safer than calling `process.exit()`.
613 * In `Worker` threads, this function stops the current thread rather
614 * than the current process.
616 * @param [code=0] The exit code.
618 exit(code?: number): never;
620 * A number which will be the process exit code, when the process either
621 * exits gracefully, or is exited via {@link exit} without specifying
624 * Specifying a code to {@link exit} will override any
625 * previous setting of `process.exitCode`.
628 exitCode?: number | undefined;
630 * The `process.getgid()` method returns the numerical group identity of the
631 * process. (See [`getgid(2)`](http://man7.org/linux/man-pages/man2/getgid.2.html).)
634 * import process from 'process';
636 * if (process.getgid) {
637 * console.log(`Current gid: ${process.getgid()}`);
641 * This function is only available on POSIX platforms (i.e. not Windows or
645 getgid?: () => number;
647 * The `process.setgid()` method sets the group identity of the process. (See [`setgid(2)`](http://man7.org/linux/man-pages/man2/setgid.2.html).) The `id` can be passed as either a
648 * numeric ID or a group name
649 * string. If a group name is specified, this method blocks while resolving the
650 * associated numeric ID.
653 * import process from 'process';
655 * if (process.getgid && process.setgid) {
656 * console.log(`Current gid: ${process.getgid()}`);
658 * process.setgid(501);
659 * console.log(`New gid: ${process.getgid()}`);
661 * console.log(`Failed to set gid: ${err}`);
666 * This function is only available on POSIX platforms (i.e. not Windows or
668 * This feature is not available in `Worker` threads.
670 * @param id The group name or ID
672 setgid?: (id: number | string) => void;
674 * The `process.getuid()` method returns the numeric user identity of the process.
675 * (See [`getuid(2)`](http://man7.org/linux/man-pages/man2/getuid.2.html).)
678 * import process from 'process';
680 * if (process.getuid) {
681 * console.log(`Current uid: ${process.getuid()}`);
685 * This function is only available on POSIX platforms (i.e. not Windows or
689 getuid?: () => number;
691 * The `process.setuid(id)` method sets the user identity of the process. (See [`setuid(2)`](http://man7.org/linux/man-pages/man2/setuid.2.html).) The `id` can be passed as either a
692 * numeric ID or a username string.
693 * If a username is specified, the method blocks while resolving the associated
697 * import process from 'process';
699 * if (process.getuid && process.setuid) {
700 * console.log(`Current uid: ${process.getuid()}`);
702 * process.setuid(501);
703 * console.log(`New uid: ${process.getuid()}`);
705 * console.log(`Failed to set uid: ${err}`);
710 * This function is only available on POSIX platforms (i.e. not Windows or
712 * This feature is not available in `Worker` threads.
715 setuid?: (id: number | string) => void;
717 * The `process.geteuid()` method returns the numerical effective user identity of
718 * the process. (See [`geteuid(2)`](http://man7.org/linux/man-pages/man2/geteuid.2.html).)
721 * import process from 'process';
723 * if (process.geteuid) {
724 * console.log(`Current uid: ${process.geteuid()}`);
728 * This function is only available on POSIX platforms (i.e. not Windows or
732 geteuid?: () => number;
734 * The `process.seteuid()` method sets the effective user identity of the process.
735 * (See [`seteuid(2)`](http://man7.org/linux/man-pages/man2/seteuid.2.html).) The `id` can be passed as either a numeric ID or a username
736 * string. If a username is specified, the method blocks while resolving the
737 * associated numeric ID.
740 * import process from 'process';
742 * if (process.geteuid && process.seteuid) {
743 * console.log(`Current uid: ${process.geteuid()}`);
745 * process.seteuid(501);
746 * console.log(`New uid: ${process.geteuid()}`);
748 * console.log(`Failed to set uid: ${err}`);
753 * This function is only available on POSIX platforms (i.e. not Windows or
755 * This feature is not available in `Worker` threads.
757 * @param id A user name or ID
759 seteuid?: (id: number | string) => void;
761 * The `process.getegid()` method returns the numerical effective group identity
762 * of the Node.js process. (See [`getegid(2)`](http://man7.org/linux/man-pages/man2/getegid.2.html).)
765 * import process from 'process';
767 * if (process.getegid) {
768 * console.log(`Current gid: ${process.getegid()}`);
772 * This function is only available on POSIX platforms (i.e. not Windows or
776 getegid?: () => number;
778 * The `process.setegid()` method sets the effective group identity of the process.
779 * (See [`setegid(2)`](http://man7.org/linux/man-pages/man2/setegid.2.html).) The `id` can be passed as either a numeric ID or a group
780 * name string. If a group name is specified, this method blocks while resolving
781 * the associated a numeric ID.
784 * import process from 'process';
786 * if (process.getegid && process.setegid) {
787 * console.log(`Current gid: ${process.getegid()}`);
789 * process.setegid(501);
790 * console.log(`New gid: ${process.getegid()}`);
792 * console.log(`Failed to set gid: ${err}`);
797 * This function is only available on POSIX platforms (i.e. not Windows or
799 * This feature is not available in `Worker` threads.
801 * @param id A group name or ID
803 setegid?: (id: number | string) => void;
805 * The `process.getgroups()` method returns an array with the supplementary group
806 * IDs. POSIX leaves it unspecified if the effective group ID is included but
807 * Node.js ensures it always is.
810 * import process from 'process';
812 * if (process.getgroups) {
813 * console.log(process.getgroups()); // [ 16, 21, 297 ]
817 * This function is only available on POSIX platforms (i.e. not Windows or
821 getgroups?: () => number[];
823 * The `process.setgroups()` method sets the supplementary group IDs for the
824 * Node.js process. This is a privileged operation that requires the Node.js
825 * process to have `root` or the `CAP_SETGID` capability.
827 * The `groups` array can contain numeric group IDs, group names, or both.
830 * import process from 'process';
832 * if (process.getgroups && process.setgroups) {
834 * process.setgroups([501]);
835 * console.log(process.getgroups()); // new groups
837 * console.log(`Failed to set groups: ${err}`);
842 * This function is only available on POSIX platforms (i.e. not Windows or
844 * This feature is not available in `Worker` threads.
847 setgroups?: (groups: ReadonlyArray<string | number>) => void;
849 * The `process.setUncaughtExceptionCaptureCallback()` function sets a function
850 * that will be invoked when an uncaught exception occurs, which will receive the
851 * exception value itself as its first argument.
853 * If such a function is set, the `'uncaughtException'` event will
854 * not be emitted. If `--abort-on-uncaught-exception` was passed from the
855 * command line or set through `v8.setFlagsFromString()`, the process will
856 * not abort. Actions configured to take place on exceptions such as report
857 * generations will be affected too
859 * To unset the capture function,`process.setUncaughtExceptionCaptureCallback(null)` may be used. Calling this
860 * method with a non-`null` argument while another capture function is set will
863 * Using this function is mutually exclusive with using the deprecated `domain` built-in module.
866 setUncaughtExceptionCaptureCallback(cb: ((err: Error) => void) | null): void;
868 * Indicates whether a callback has been set using {@link setUncaughtExceptionCaptureCallback}.
871 hasUncaughtExceptionCaptureCallback(): boolean;
873 * The `process.version` property contains the Node.js version string.
876 * import { version } from 'process';
878 * console.log(`Version: ${version}`);
879 * // Version: v14.8.0
882 * To get the version string without the prepended _v_, use`process.versions.node`.
885 readonly version: string;
887 * The `process.versions` property returns an object listing the version strings of
888 * Node.js and its dependencies. `process.versions.modules` indicates the current
889 * ABI version, which is increased whenever a C++ API changes. Node.js will refuse
890 * to load modules that were compiled against a different module ABI version.
893 * import { versions } from 'process';
895 * console.log(versions);
898 * Will generate an object similar to:
902 * v8: '7.0.276.38-node.18',
919 readonly versions: ProcessVersions;
921 * The `process.config` property returns an `Object` containing the JavaScript
922 * representation of the configure options used to compile the current Node.js
923 * executable. This is the same as the `config.gypi` file that was produced when
924 * running the `./configure` script.
926 * An example of the possible output looks like:
932 * default_configuration: 'Release',
939 * napi_build_version: 5,
940 * node_install_npm: 'true',
942 * node_shared_cares: 'false',
943 * node_shared_http_parser: 'false',
944 * node_shared_libuv: 'false',
945 * node_shared_zlib: 'false',
946 * node_use_dtrace: 'false',
947 * node_use_openssl: 'true',
948 * node_shared_openssl: 'false',
949 * strict_aliasing: 'true',
950 * target_arch: 'x64',
956 * The `process.config` property is **not** read-only and there are existing
957 * modules in the ecosystem that are known to extend, modify, or entirely replace
958 * the value of `process.config`.
960 * Modifying the `process.config` property, or any child-property of the`process.config` object has been deprecated. The `process.config` will be made
961 * read-only in a future release.
964 readonly config: ProcessConfig;
966 * The `process.kill()` method sends the `signal` to the process identified by`pid`.
968 * Signal names are strings such as `'SIGINT'` or `'SIGHUP'`. See `Signal Events` and [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for more information.
970 * This method will throw an error if the target `pid` does not exist. As a special
971 * case, a signal of `0` can be used to test for the existence of a process.
972 * Windows platforms will throw an error if the `pid` is used to kill a process
975 * Even though the name of this function is `process.kill()`, it is really just a
976 * signal sender, like the `kill` system call. The signal sent may do something
977 * other than kill the target process.
980 * import process, { kill } from 'process';
982 * process.on('SIGHUP', () => {
983 * console.log('Got SIGHUP signal.');
987 * console.log('Exiting.');
991 * kill(process.pid, 'SIGHUP');
994 * When `SIGUSR1` is received by a Node.js process, Node.js will start the
995 * debugger. See `Signal Events`.
997 * @param pid A process ID
998 * @param [signal='SIGTERM'] The signal to send, either as a string or number.
1000 kill(pid: number, signal?: string | number): true;
1002 * The `process.pid` property returns the PID of the process.
1005 * import { pid } from 'process';
1007 * console.log(`This process is pid ${pid}`);
1011 readonly pid: number;
1013 * The `process.ppid` property returns the PID of the parent of the
1017 * import { ppid } from 'process';
1019 * console.log(`The parent process is pid ${ppid}`);
1021 * @since v9.2.0, v8.10.0, v6.13.0
1023 readonly ppid: number;
1025 * The `process.title` property returns the current process title (i.e. returns
1026 * the current value of `ps`). Assigning a new value to `process.title` modifies
1027 * the current value of `ps`.
1029 * When a new value is assigned, different platforms will impose different maximum
1030 * length restrictions on the title. Usually such restrictions are quite limited.
1031 * For instance, on Linux and macOS, `process.title` is limited to the size of the
1032 * binary name plus the length of the command-line arguments because setting the`process.title` overwrites the `argv` memory of the process. Node.js v0.8
1033 * allowed for longer process title strings by also overwriting the `environ`memory but that was potentially insecure and confusing in some (rather obscure)
1036 * Assigning a value to `process.title` might not result in an accurate label
1037 * within process manager applications such as macOS Activity Monitor or Windows
1043 * The operating system CPU architecture for which the Node.js binary was compiled.
1044 * Possible values are: `'arm'`, `'arm64'`, `'ia32'`, `'mips'`,`'mipsel'`, `'ppc'`,`'ppc64'`, `'s390'`, `'s390x'`, and `'x64'`.
1047 * import { arch } from 'process';
1049 * console.log(`This processor architecture is ${arch}`);
1053 readonly arch: Architecture;
1055 * The `process.platform` property returns a string identifying the operating
1056 * system platform for which the Node.js binary was compiled.
1058 * Currently possible values are:
1069 * import { platform } from 'process';
1071 * console.log(`This platform is ${platform}`);
1074 * The value `'android'` may also be returned if the Node.js is built on the
1075 * Android operating system. However, Android support in Node.js [is experimental](https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os).
1078 readonly platform: Platform;
1080 * The `process.mainModule` property provides an alternative way of retrieving `require.main`. The difference is that if the main module changes at
1081 * runtime, `require.main` may still refer to the original main module in
1082 * modules that were required before the change occurred. Generally, it's
1083 * safe to assume that the two refer to the same module.
1085 * As with `require.main`, `process.mainModule` will be `undefined` if there
1086 * is no entry script.
1088 * @deprecated Since v14.0.0 - Use `main` instead.
1090 mainModule?: Module | undefined;
1091 memoryUsage: MemoryUsageFn;
1093 * The `process.cpuUsage()` method returns the user and system CPU time usage of
1094 * the current process, in an object with properties `user` and `system`, whose
1095 * values are microsecond values (millionth of a second). These values measure time
1096 * spent in user and system code respectively, and may end up being greater than
1097 * actual elapsed time if multiple CPU cores are performing work for this process.
1099 * The result of a previous call to `process.cpuUsage()` can be passed as the
1100 * argument to the function, to get a diff reading.
1103 * import { cpuUsage } from 'process';
1105 * const startUsage = cpuUsage();
1106 * // { user: 38579, system: 6986 }
1108 * // spin the CPU for 500 milliseconds
1109 * const now = Date.now();
1110 * while (Date.now() - now < 500);
1112 * console.log(cpuUsage(startUsage));
1113 * // { user: 514883, system: 11226 }
1116 * @param previousValue A previous return value from calling `process.cpuUsage()`
1118 cpuUsage(previousValue?: CpuUsage): CpuUsage;
1120 * `process.nextTick()` adds `callback` to the "next tick queue". This queue is
1121 * fully drained after the current operation on the JavaScript stack runs to
1122 * completion and before the event loop is allowed to continue. It's possible to
1123 * create an infinite loop if one were to recursively call `process.nextTick()`.
1124 * See the [Event Loop](https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick) guide for more background.
1127 * import { nextTick } from 'process';
1129 * console.log('start');
1131 * console.log('nextTick callback');
1133 * console.log('scheduled');
1137 * // nextTick callback
1140 * This is important when developing APIs in order to give users the opportunity
1141 * to assign event handlers _after_ an object has been constructed but before any
1145 * import { nextTick } from 'process';
1147 * function MyThing(options) {
1148 * this.setupOptions(options);
1151 * this.startDoingStuff();
1155 * const thing = new MyThing();
1156 * thing.getReadyForStuff();
1158 * // thing.startDoingStuff() gets called now, not before.
1161 * It is very important for APIs to be either 100% synchronous or 100%
1162 * asynchronous. Consider this example:
1165 * // WARNING! DO NOT USE! BAD UNSAFE HAZARD!
1166 * function maybeSync(arg, cb) {
1172 * fs.stat('file', cb);
1176 * This API is hazardous because in the following case:
1179 * const maybeTrue = Math.random() > 0.5;
1181 * maybeSync(maybeTrue, () => {
1188 * It is not clear whether `foo()` or `bar()` will be called first.
1190 * The following approach is much better:
1193 * import { nextTick } from 'process';
1195 * function definitelyAsync(arg, cb) {
1201 * fs.stat('file', cb);
1205 * @param args Additional arguments to pass when invoking the `callback`
1207 nextTick(callback: Function, ...args: any[]): void;
1209 * The `process.release` property returns an `Object` containing metadata related
1210 * to the current release, including URLs for the source tarball and headers-only
1213 * `process.release` contains the following properties:
1219 * sourceUrl: 'https://nodejs.org/download/release/v12.18.1/node-v12.18.1.tar.gz',
1220 * headersUrl: 'https://nodejs.org/download/release/v12.18.1/node-v12.18.1-headers.tar.gz',
1221 * libUrl: 'https://nodejs.org/download/release/v12.18.1/win-x64/node.lib'
1225 * In custom builds from non-release versions of the source tree, only the`name` property may be present. The additional properties should not be
1226 * relied upon to exist.
1229 readonly release: ProcessRelease;
1241 * `process.umask()` returns the Node.js process's file mode creation mask. Child
1242 * processes inherit the mask from the parent process.
1244 * @deprecated Calling `process.umask()` with no argument causes the process-wide umask to be written twice. This introduces a race condition between threads, and is a potential *
1245 * security vulnerability. There is no safe, cross-platform alternative API.
1249 * Can only be set if not in worker thread.
1251 umask(mask: string | number): number;
1253 * The `process.uptime()` method returns the number of seconds the current Node.js
1254 * process has been running.
1256 * The return value includes fractions of a second. Use `Math.floor()` to get whole
1263 * If Node.js is spawned with an IPC channel, the `process.send()` method can be
1264 * used to send messages to the parent process. Messages will be received as a `'message'` event on the parent's `ChildProcess` object.
1266 * If Node.js was not spawned with an IPC channel, `process.send` will be`undefined`.
1268 * The message goes through serialization and parsing. The resulting message might
1269 * not be the same as what is originally sent.
1271 * @param options used to parameterize the sending of certain types of handles.`options` supports the following properties:
1277 swallowErrors?: boolean | undefined;
1279 callback?: (error: Error | null) => void
1282 * If the Node.js process is spawned with an IPC channel (see the `Child Process` and `Cluster` documentation), the `process.disconnect()` method will close the
1283 * IPC channel to the parent process, allowing the child process to exit gracefully
1284 * once there are no other connections keeping it alive.
1286 * The effect of calling `process.disconnect()` is the same as calling `ChildProcess.disconnect()` from the parent process.
1288 * If the Node.js process was not spawned with an IPC channel,`process.disconnect()` will be `undefined`.
1293 * If the Node.js process is spawned with an IPC channel (see the `Child Process` and `Cluster` documentation), the `process.connected` property will return`true` so long as the IPC
1294 * channel is connected and will return `false` after`process.disconnect()` is called.
1296 * Once `process.connected` is `false`, it is no longer possible to send messages
1297 * over the IPC channel using `process.send()`.
1302 * The `process.allowedNodeEnvironmentFlags` property is a special,
1303 * read-only `Set` of flags allowable within the `NODE_OPTIONS` environment variable.
1305 * `process.allowedNodeEnvironmentFlags` extends `Set`, but overrides`Set.prototype.has` to recognize several different possible flag
1306 * representations. `process.allowedNodeEnvironmentFlags.has()` will
1307 * return `true` in the following cases:
1309 * * Flags may omit leading single (`-`) or double (`--`) dashes; e.g.,`inspect-brk` for `--inspect-brk`, or `r` for `-r`.
1310 * * Flags passed through to V8 (as listed in `--v8-options`) may replace
1311 * one or more _non-leading_ dashes for an underscore, or vice-versa;
1312 * e.g., `--perf_basic_prof`, `--perf-basic-prof`, `--perf_basic-prof`,
1314 * * Flags may contain one or more equals (`=`) characters; all
1315 * characters after and including the first equals will be ignored;
1316 * e.g., `--stack-trace-limit=100`.
1317 * * Flags _must_ be allowable within `NODE_OPTIONS`.
1319 * When iterating over `process.allowedNodeEnvironmentFlags`, flags will
1320 * appear only _once_; each will begin with one or more dashes. Flags
1321 * passed through to V8 will contain underscores instead of non-leading
1325 * import { allowedNodeEnvironmentFlags } from 'process';
1327 * allowedNodeEnvironmentFlags.forEach((flag) => {
1330 * // --abort_on_uncaught_exception
1335 * The methods `add()`, `clear()`, and `delete()` of`process.allowedNodeEnvironmentFlags` do nothing, and will fail
1338 * If Node.js was compiled _without_ `NODE_OPTIONS` support (shown in {@link config}), `process.allowedNodeEnvironmentFlags` will
1339 * contain what _would have_ been allowable.
1342 allowedNodeEnvironmentFlags: ReadonlySet<string>;
1344 * `process.report` is an object whose methods are used to generate diagnostic
1345 * reports for the current process. Additional documentation is available in the `report documentation`.
1348 report?: ProcessReport | undefined;
1351 * import { resourceUsage } from 'process';
1353 * console.log(resourceUsage());
1357 * userCPUTime: 82872,
1358 * systemCPUTime: 4143,
1360 * sharedMemorySize: 0,
1361 * unsharedDataSize: 0,
1362 * unsharedStackSize: 0,
1363 * minorPageFault: 2469,
1364 * majorPageFault: 0,
1371 * voluntaryContextSwitches: 79,
1372 * involuntaryContextSwitches: 1
1377 * @return the resource usage for the current process. All of these values come from the `uv_getrusage` call which returns a [`uv_rusage_t` struct][uv_rusage_t].
1379 resourceUsage(): ResourceUsage;
1381 * The `process.traceDeprecation` property indicates whether the`--trace-deprecation` flag is set on the current Node.js process. See the
1382 * documentation for the `'warning' event` and the `emitWarning() method` for more information about this
1386 traceDeprecation: boolean;
1388 addListener(event: 'beforeExit', listener: BeforeExitListener): this;
1389 addListener(event: 'disconnect', listener: DisconnectListener): this;
1390 addListener(event: 'exit', listener: ExitListener): this;
1391 addListener(event: 'rejectionHandled', listener: RejectionHandledListener): this;
1392 addListener(event: 'uncaughtException', listener: UncaughtExceptionListener): this;
1393 addListener(event: 'uncaughtExceptionMonitor', listener: UncaughtExceptionListener): this;
1394 addListener(event: 'unhandledRejection', listener: UnhandledRejectionListener): this;
1395 addListener(event: 'warning', listener: WarningListener): this;
1396 addListener(event: 'message', listener: MessageListener): this;
1397 addListener(event: Signals, listener: SignalsListener): this;
1398 addListener(event: 'multipleResolves', listener: MultipleResolveListener): this;
1399 addListener(event: 'worker', listener: WorkerListener): this;
1400 emit(event: 'beforeExit', code: number): boolean;
1401 emit(event: 'disconnect'): boolean;
1402 emit(event: 'exit', code: number): boolean;
1403 emit(event: 'rejectionHandled', promise: Promise<unknown>): boolean;
1404 emit(event: 'uncaughtException', error: Error): boolean;
1405 emit(event: 'uncaughtExceptionMonitor', error: Error): boolean;
1406 emit(event: 'unhandledRejection', reason: unknown, promise: Promise<unknown>): boolean;
1407 emit(event: 'warning', warning: Error): boolean;
1408 emit(event: 'message', message: unknown, sendHandle: unknown): this;
1409 emit(event: Signals, signal?: Signals): boolean;
1410 emit(event: 'multipleResolves', type: MultipleResolveType, promise: Promise<unknown>, value: unknown): this;
1411 emit(event: 'worker', listener: WorkerListener): this;
1412 on(event: 'beforeExit', listener: BeforeExitListener): this;
1413 on(event: 'disconnect', listener: DisconnectListener): this;
1414 on(event: 'exit', listener: ExitListener): this;
1415 on(event: 'rejectionHandled', listener: RejectionHandledListener): this;
1416 on(event: 'uncaughtException', listener: UncaughtExceptionListener): this;
1417 on(event: 'uncaughtExceptionMonitor', listener: UncaughtExceptionListener): this;
1418 on(event: 'unhandledRejection', listener: UnhandledRejectionListener): this;
1419 on(event: 'warning', listener: WarningListener): this;
1420 on(event: 'message', listener: MessageListener): this;
1421 on(event: Signals, listener: SignalsListener): this;
1422 on(event: 'multipleResolves', listener: MultipleResolveListener): this;
1423 on(event: 'worker', listener: WorkerListener): this;
1424 on(event: string | symbol, listener: (...args: any[]) => void): this;
1425 once(event: 'beforeExit', listener: BeforeExitListener): this;
1426 once(event: 'disconnect', listener: DisconnectListener): this;
1427 once(event: 'exit', listener: ExitListener): this;
1428 once(event: 'rejectionHandled', listener: RejectionHandledListener): this;
1429 once(event: 'uncaughtException', listener: UncaughtExceptionListener): this;
1430 once(event: 'uncaughtExceptionMonitor', listener: UncaughtExceptionListener): this;
1431 once(event: 'unhandledRejection', listener: UnhandledRejectionListener): this;
1432 once(event: 'warning', listener: WarningListener): this;
1433 once(event: 'message', listener: MessageListener): this;
1434 once(event: Signals, listener: SignalsListener): this;
1435 once(event: 'multipleResolves', listener: MultipleResolveListener): this;
1436 once(event: 'worker', listener: WorkerListener): this;
1437 once(event: string | symbol, listener: (...args: any[]) => void): this;
1438 prependListener(event: 'beforeExit', listener: BeforeExitListener): this;
1439 prependListener(event: 'disconnect', listener: DisconnectListener): this;
1440 prependListener(event: 'exit', listener: ExitListener): this;
1441 prependListener(event: 'rejectionHandled', listener: RejectionHandledListener): this;
1442 prependListener(event: 'uncaughtException', listener: UncaughtExceptionListener): this;
1443 prependListener(event: 'uncaughtExceptionMonitor', listener: UncaughtExceptionListener): this;
1444 prependListener(event: 'unhandledRejection', listener: UnhandledRejectionListener): this;
1445 prependListener(event: 'warning', listener: WarningListener): this;
1446 prependListener(event: 'message', listener: MessageListener): this;
1447 prependListener(event: Signals, listener: SignalsListener): this;
1448 prependListener(event: 'multipleResolves', listener: MultipleResolveListener): this;
1449 prependListener(event: 'worker', listener: WorkerListener): this;
1450 prependOnceListener(event: 'beforeExit', listener: BeforeExitListener): this;
1451 prependOnceListener(event: 'disconnect', listener: DisconnectListener): this;
1452 prependOnceListener(event: 'exit', listener: ExitListener): this;
1453 prependOnceListener(event: 'rejectionHandled', listener: RejectionHandledListener): this;
1454 prependOnceListener(event: 'uncaughtException', listener: UncaughtExceptionListener): this;
1455 prependOnceListener(event: 'uncaughtExceptionMonitor', listener: UncaughtExceptionListener): this;
1456 prependOnceListener(event: 'unhandledRejection', listener: UnhandledRejectionListener): this;
1457 prependOnceListener(event: 'warning', listener: WarningListener): this;
1458 prependOnceListener(event: 'message', listener: MessageListener): this;
1459 prependOnceListener(event: Signals, listener: SignalsListener): this;
1460 prependOnceListener(event: 'multipleResolves', listener: MultipleResolveListener): this;
1461 prependOnceListener(event: 'worker', listener: WorkerListener): this;
1462 listeners(event: 'beforeExit'): BeforeExitListener[];
1463 listeners(event: 'disconnect'): DisconnectListener[];
1464 listeners(event: 'exit'): ExitListener[];
1465 listeners(event: 'rejectionHandled'): RejectionHandledListener[];
1466 listeners(event: 'uncaughtException'): UncaughtExceptionListener[];
1467 listeners(event: 'uncaughtExceptionMonitor'): UncaughtExceptionListener[];
1468 listeners(event: 'unhandledRejection'): UnhandledRejectionListener[];
1469 listeners(event: 'warning'): WarningListener[];
1470 listeners(event: 'message'): MessageListener[];
1471 listeners(event: Signals): SignalsListener[];
1472 listeners(event: 'multipleResolves'): MultipleResolveListener[];
1473 listeners(event: 'worker'): WorkerListener[];
1479 declare module 'node:process' {
1480 import process = require('process');