Process
Properties
The process.allowedNodeEnvironmentFlags
property is a special, read-only Set
of flags allowable within the NODE_OPTIONS
environment variable.
The operating system CPU architecture for which the Node.js binary was compiled. Possible values are: 'arm'
, 'arm64'
, 'ia32'
, 'loong64'
, 'mips'
, 'mipsel'
, 'ppc'
, 'ppc64'
, 'riscv64'
, 's390'
, 's390x'
, and 'x64'
.
The process.argv
property returns an array containing the command-line arguments passed when the Node.js process was launched. The first element will be {@link execPath}. See process.argv0
if access to the original value of argv[0]
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.
If the Node.js process was spawned with an IPC channel, the process.channel property is a reference to the IPC channel. If no IPC channel exists, this property is undefined.
The process.config
property returns a frozen Object
containing the JavaScript representation of the configure options used to compile the current Node.js executable. This is the same as the config.gypi
file that was produced when running the ./configure
script.
The process.env
property returns an object containing the user environment. See environ(7)
.
The process.execArgv
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 {@link argv} 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.
The process.getegid()
method returns the numerical effective group identity of the Node.js process. (See getegid(2)
.)
The process.geteuid()
method returns the numerical effective user identity of the process. (See geteuid(2)
.)
The process.getgroups()
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.
The process.mainModule
property provides an alternative way of retrieving require.main
. The difference is that if the main module changes at runtime, require.main
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.
This API is available through the --experimental-permission flag.
The process.release
property returns an Object
containing metadata related to the current release, including URLs for the source tarball and headers-only tarball.
process.report
is an object whose methods are used to generate diagnostic reports for the current process. Additional documentation is available in the report documentation.
If Node.js is spawned with an IPC channel, the process.send()
method can be used to send messages to the parent process. Messages will be received as a 'message'
event on the parent's ChildProcess
object.
The process.setegid()
method sets the effective group identity of the process. (See setegid(2)
.) The id
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.
The process.seteuid()
method sets the effective user identity of the process. (See seteuid(2)
.) The id
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.
The process.setgroups()
method sets the supplementary group IDs for the Node.js process. This is a privileged operation that requires the Node.js process to have root
or the CAP_SETGID
capability.
The process.sourceMapsEnabled
property returns whether the Source Map v3 support for stack traces is enabled.
The process.stderr
property returns a stream connected tostderr
(fd 2
). It is a net.Socket
(which is a Duplex
stream) unless fd 2
refers to a file, in which case it is a Writable
stream.
The process.stdin
property returns a stream connected tostdin
(fd 0
). It is a net.Socket
(which is a Duplex
stream) unless fd 0
refers to a file, in which case it is a Readable
stream.
The process.stdout
property returns a stream connected tostdout
(fd 1
). It is a net.Socket
(which is a Duplex
stream) unless fd 1
refers to a file, in which case it is a Writable
stream.
The initial value of process.throwDeprecation
indicates whether the --throw-deprecation
flag is set on the current Node.js process. process.throwDeprecation
is mutable, so whether or not deprecation warnings result in errors may be altered at runtime. See the documentation for the 'warning' event and the emitWarning() method for more information.
The process.traceDeprecation
property indicates whether the --trace-deprecation
flag is set on the current Node.js process. See the documentation for the 'warning' event
and the emitWarning() method
for more information about this flag's behavior.
The process.versions
property returns an object listing the version strings of Node.js and its dependencies. process.versions.modules
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.
Functions
Alias for emitter.on(eventName, listener)
.
Gets the amount of free memory that is still available to the process (in bytes). See uv_get_available_memory
for more information.
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, 0
is returned.
The process.cpuUsage()
method returns the user and system CPU time usage of the current process, in an object with properties user
and system
, 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.
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 IPC channel to the parent process, allowing the child process to exit gracefully once there are no other connections keeping it alive.
The process.dlopen()
method allows dynamically loading shared objects. It is primarily used by require()
to load C++ Addons, and should not be used directly, except in special cases. In other words, require()
should be preferred over process.dlopen()
unless there are specific reasons such as custom dlopen flags or loading from ES modules.
The process.emitWarning()
method can be used to emit custom or application specific process warnings. These can be listened for by adding a handler to the 'warning'
event.
Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbol
s.
The process.exit()
method instructs Node.js to terminate the process synchronously with an exit status of code
. If code
is omitted, exit uses either the 'success' code 0
or the value of process.exitCode
if it has been set. Node.js will not terminate until all the 'exit'
event listeners are called.
The process.getActiveResourcesInfo()
method returns an array of strings containing the types of the active resources that are currently keeping the event loop alive.
Provides a way to load built-in modules in a globally available function.
Returns the current max listener value for the EventEmitter
which is either set by emitter.setMaxListeners(n)
or defaults to {@link defaultMaxListeners}.
Indicates whether a callback has been set using {@link setUncaughtExceptionCaptureCallback}.
Returns the number of listeners listening for the event named eventName
. If listener
is provided, it will return how many times the listener is found in the list of the listeners of the event.
Returns a copy of the array of listeners for the event named eventName
.
Loads the environment configuration from a .env
file into process.env
. If the file is not found, error will be thrown.
process.nextTick()
adds callback
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 process.nextTick()
. See the Event Loop guide for more background.
Alias for emitter.removeListener()
.
Adds the listener
function to the end of the listeners array for the event named eventName
. No checks are made to see if the listener
has already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple times.
Adds a one-time listener
function for the event named eventName
. The next time eventName
is triggered, this listener is removed and then invoked.
Adds the listener
function to the beginning of the listeners array for the event named eventName
. No checks are made to see if the listener
has already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple times.
Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this listener is removed, and then invoked.
Returns a copy of the array of listeners for the event named eventName
, including any wrappers (such as those created by .once()
).
Removes all listeners, or those of the specified eventName
.
Removes the specified listener
from the listener array for the event named eventName
.
By default EventEmitter
s will print a warning if more than 10
listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners()
method allows the limit to be modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
This function enables or disables the Source Map v3 support for stack traces.
The process.setUncaughtExceptionCaptureCallback()
function sets a function that will be invoked when an uncaught exception occurs, which will receive the exception value itself as its first argument.