{ "source": "doc/api/process.md", "globals": [ { "textRaw": "Process", "name": "Process", "type": "global", "desc": "
The process
object is a global
that provides information about, and control\nover, the current Node.js process. As a global, it is always available to\nNode.js applications without using require()
.
The process
object is an instance of EventEmitter
.
The 'beforeExit'
event is emitted when Node.js empties its event loop and has\nno additional work to schedule. Normally, the Node.js process will exit when\nthere is no work scheduled, but a listener registered on the 'beforeExit'
\nevent can make asynchronous calls, and thereby cause the Node.js process to\ncontinue.
The listener callback function is invoked with the value of\nprocess.exitCode
passed as the only argument.
The 'beforeExit'
event is not emitted for conditions causing explicit\ntermination, such as calling process.exit()
or uncaught exceptions.
The 'beforeExit'
should not be used as an alternative to the 'exit'
event\nunless the intention is to schedule additional work.
If the Node.js process is spawned with an IPC channel (see the Child Process\nand Cluster documentation), the 'disconnect'
event will be emitted when\nthe IPC channel is closed.
The 'exit'
event is emitted when the Node.js process is about to exit as a\nresult of either:
process.exit()
method being called explicitly;There is no way to prevent the exiting of the event loop at this point, and once\nall 'exit'
listeners have finished running the Node.js process will terminate.
The listener callback function is invoked with the exit code specified either\nby the process.exitCode
property, or the exitCode
argument passed to the\nprocess.exit()
method, as the only argument.
For example:
\nprocess.on('exit', (code) => {\n console.log(`About to exit with code: ${code}`);\n});\n
\nListener functions must only perform synchronous operations. The Node.js\nprocess will exit immediately after calling the 'exit'
event listeners\ncausing any additional work still queued in the event loop to be abandoned.\nIn the following example, for instance, the timeout will never occur:
process.on('exit', (code) => {\n setTimeout(() => {\n console.log('This will not run');\n }, 0);\n});\n
\n",
"params": []
},
{
"textRaw": "Event: 'message'",
"type": "event",
"name": "message",
"meta": {
"added": [
"v0.5.10"
],
"changes": []
},
"desc": "If the Node.js process is spawned with an IPC channel (see the Child Process\nand Cluster documentation), the 'message'
event is emitted whenever a\nmessage sent by a parent process using childprocess.send()
is received by\nthe child process.
The listener callback is invoked with the following arguments:
\nmessage
{Object} a parsed JSON object or primitive valuesendHandle
{Handle object} a net.Socket
or net.Server
object, or\nundefined.The 'rejectionHandled'
event is emitted whenever a Promise
has been rejected\nand an error handler was attached to it (using promise.catch()
, for\nexample) later than one turn of the Node.js event loop.
The listener callback is invoked with a reference to the rejected Promise
as\nthe only argument.
The Promise
object would have previously been emitted in an\n'unhandledRejection'
event, but during the course of processing gained a\nrejection handler.
There is no notion of a top level for a Promise
chain at which rejections can\nalways be handled. Being inherently asynchronous in nature, a Promise
\nrejection can be handled at a future point in time — possibly much later than\nthe event loop turn it takes for the 'unhandledRejection'
event to be emitted.
Another way of stating this is that, unlike in synchronous code where there is\nan ever-growing list of unhandled exceptions, with Promises there can be a\ngrowing-and-shrinking list of unhandled rejections.
\nIn synchronous code, the 'uncaughtException'
event is emitted when the list of\nunhandled exceptions grows.
In asynchronous code, the 'unhandledRejection'
event is emitted when the list\nof unhandled rejections grows, and the 'rejectionHandled'
event is emitted\nwhen the list of unhandled rejections shrinks.
For example:
\nconst unhandledRejections = new Map();\nprocess.on('unhandledRejection', (reason, p) => {\n unhandledRejections.set(p, reason);\n});\nprocess.on('rejectionHandled', (p) => {\n unhandledRejections.delete(p);\n});\n
\nIn this example, the unhandledRejections
Map
will grow and shrink over time,\nreflecting rejections that start unhandled and then become handled. It is\npossible to record such errors in an error log, either periodically (which is\nlikely best for long-running application) or upon process exit (which is likely\nmost convenient for scripts).
The 'uncaughtException'
event is emitted when an uncaught JavaScript\nexception bubbles all the way back to the event loop. By default, Node.js\nhandles such exceptions by printing the stack trace to stderr
and exiting.\nAdding a handler for the 'uncaughtException'
event overrides this default\nbehavior.
The listener function is called with the Error
object passed as the only\nargument.
For example:
\nprocess.on('uncaughtException', (err) => {\n fs.writeSync(1, `Caught exception: ${err}`);\n});\n\nsetTimeout(() => {\n console.log('This will still run.');\n}, 500);\n\n// Intentionally cause an exception, but don't catch it.\nnonexistentFunc();\nconsole.log('This will not run.');\n
\n",
"modules": [
{
"textRaw": "Warning: Using `'uncaughtException'` correctly",
"name": "warning:_using_`'uncaughtexception'`_correctly",
"desc": "Note that 'uncaughtException'
is a crude mechanism for exception handling\nintended to be used only as a last resort. The event should not be used as\nan equivalent to On Error Resume Next
. Unhandled exceptions inherently mean\nthat an application is in an undefined state. Attempting to resume application\ncode without properly recovering from the exception can cause additional\nunforeseen and unpredictable issues.
Exceptions thrown from within the event handler will not be caught. Instead the\nprocess will exit with a non-zero exit code and the stack trace will be printed.\nThis is to avoid infinite recursion.
\nAttempting to resume normally after an uncaught exception can be similar to\npulling out of the power cord when upgrading a computer -- nine out of ten\ntimes nothing happens - but the 10th time, the system becomes corrupted.
\nThe correct use of 'uncaughtException'
is to perform synchronous cleanup\nof allocated resources (e.g. file descriptors, handles, etc) before shutting\ndown the process. It is not safe to resume normal operation after\n'uncaughtException'
.
To restart a crashed application in a more reliable way, whether uncaughtException
\nis emitted or not, an external monitor should be employed in a separate process\nto detect application failures and recover or restart as needed.
The 'unhandledRejection
' event is emitted whenever a Promise
is rejected and\nno error handler is attached to the promise within a turn of the event loop.\nWhen programming with Promises, exceptions are encapsulated as "rejected\npromises". Rejections can be caught and handled using promise.catch()
and\nare propagated through a Promise
chain. The 'unhandledRejection'
event is\nuseful for detecting and keeping track of promises that were rejected whose\nrejections have not yet been handled.
The listener function is called with the following arguments:
\nreason
{Error|any} The object with which the promise was rejected\n(typically an Error
object).p
the Promise
that was rejected.For example:
\nprocess.on('unhandledRejection', (reason, p) => {\n console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);\n // application specific logging, throwing an error, or other logic here\n});\n\nsomePromise.then((res) => {\n return reportToUser(JSON.pasre(res)); // note the typo (`pasre`)\n}); // no `.catch` or `.then`\n
\nThe following will also trigger the 'unhandledRejection'
event to be\nemitted:
function SomeResource() {\n // Initially set the loaded status to a rejected promise\n this.loaded = Promise.reject(new Error('Resource not yet loaded!'));\n}\n\nvar resource = new SomeResource();\n// no .catch or .then on resource.loaded for at least a turn\n
\nIn this example case, it is possible to track the rejection as a developer error\nas would typically be the case for other 'unhandledRejection'
events. To\naddress such failures, a non-operational\n.catch(() => { })
handler may be attached to\nresource.loaded
, which would prevent the 'unhandledRejection'
event from\nbeing emitted. Alternatively, the 'rejectionHandled'
event may be used.
The 'warning'
event is emitted whenever Node.js emits a process warning.
A process warning is similar to an error in that it describes exceptional\nconditions that are being brought to the user's attention. However, warnings\nare not part of the normal Node.js and JavaScript error handling flow.\nNode.js can emit warnings whenever it detects bad coding practices that could\nlead to sub-optimal application performance, bugs or security vulnerabilities.
\nThe listener function is called with a single warning
argument whose value is\nan Error
object. There are three key properties that describe the warning:
name
{string} The name of the warning (currently Warning
by default).message
{string} A system-provided description of the warning.stack
{string} A stack trace to the location in the code where the warning\nwas issued.process.on('warning', (warning) => {\n console.warn(warning.name); // Print the warning name\n console.warn(warning.message); // Print the warning message\n console.warn(warning.stack); // Print the stack trace\n});\n
\nBy default, Node.js will print process warnings to stderr
. The --no-warnings
\ncommand-line option can be used to suppress the default console output but the\n'warning'
event will still be emitted by the process
object.
The following example illustrates the warning that is printed to stderr
when\ntoo many listeners have been added to an event
$ node\n> events.defaultMaxListeners = 1;\n> process.on('foo', () => {});\n> process.on('foo', () => {});\n> (node:38638) Warning: Possible EventEmitter memory leak detected. 2 foo\n... listeners added. Use emitter.setMaxListeners() to increase limit\n
\nIn contrast, the following example turns off the default warning output and\nadds a custom handler to the 'warning'
event:
$ node --no-warnings\n> var p = process.on('warning', (warning) => console.warn('Do not do that!'));\n> events.defaultMaxListeners = 1;\n> process.on('foo', () => {});\n> process.on('foo', () => {});\n> Do not do that!\n
\nThe --trace-warnings
command-line option can be used to have the default\nconsole output for warnings include the full stack trace of the warning.
Launching Node.js using the --throw-deprecation
command line flag will\ncause custom deprecation warnings to be thrown as exceptions.
Using the --trace-deprecation
command line flag will cause the custom\ndeprecation to be printed to stderr
along with the stack trace.
Using the --no-deprecation
command line flag will suppress all reporting\nof the custom deprecation.
The *-deprecation
command line flags only affect warnings that use the name\nDeprecationWarning
.
See the process.emitWarning()
method for issuing\ncustom or application-specific warnings.
Signal events will be emitted when the Node.js process receives a signal. Please\nrefer to signal(7) for a listing of standard POSIX signal names such as\nSIGINT
, SIGHUP
, etc.
The name of each event will be the uppercase common name for the signal (e.g.\n'SIGINT'
for SIGINT
signals).
For example:
\n// Begin reading from stdin so the process does not exit.\nprocess.stdin.resume();\n\nprocess.on('SIGINT', () => {\n console.log('Received SIGINT. Press Control-D to exit.');\n});\n
\nNote: An easy way to send the SIGINT
signal is with <Ctrl>-C
in most\nterminal programs.
It is important to take note of the following:
\nSIGUSR1
is reserved by Node.js to start the debugger. It's possible to\ninstall a listener but doing so will not stop the debugger from starting.SIGTERM
and SIGINT
have default handlers on non-Windows platforms that\nresets the terminal mode before exiting with code 128 + signal number
. If\none of these signals has a listener installed, its default behavior will be\nremoved (Node.js will no longer exit).SIGPIPE
is ignored by default. It can have a listener installed.SIGHUP
is generated on Windows when the console window is closed, and on\nother platforms under various similar conditions, see signal(7). It can have a\nlistener installed, however Node.js will be unconditionally terminated by\nWindows about 10 seconds later. On non-Windows platforms, the default\nbehavior of SIGHUP
is to terminate Node.js, but once a listener has been\ninstalled its default behavior will be removed.SIGTERM
is not supported on Windows, it can be listened on.SIGINT
from the terminal is supported on all platforms, and can usually be\ngenerated with CTRL+C
(though this may be configurable). It is not generated\nwhen terminal raw mode is enabled.SIGBREAK
is delivered on Windows when <Ctrl>+<Break>
is pressed, on\nnon-Windows platforms it can be listened on, but there is no way to send or\ngenerate it.SIGWINCH
is delivered when the console has been resized. On Windows, this\nwill only happen on write to the console when the cursor is being moved, or\nwhen a readable tty is used in raw mode.SIGKILL
cannot have a listener installed, it will unconditionally terminate\nNode.js on all platforms.SIGSTOP
cannot have a listener installed.SIGBUS
, SIGFPE
, SIGSEGV
and SIGILL
, when not raised artificially\n using kill(2), inherently leave the process in a state from which it is not\n safe to attempt to call JS listeners. Doing so might lead to the process\n hanging in an endless loop, since listeners attached using process.on()
are\n called asynchronously and therefore unable to correct the underlying problem.Note: Windows does not support sending signals, but Node.js offers some\nemulation with process.kill()
, and ChildProcess.kill()
. Sending\nsignal 0
can be used to test for the existence of a process. Sending SIGINT
,\nSIGTERM
, and SIGKILL
cause the unconditional termination of the target\nprocess.
Node.js will normally exit with a 0
status code when no more async\noperations are pending. The following status codes are used in other\ncases:
1
Uncaught Fatal Exception - There was an uncaught exception,\nand it was not handled by a domain or an 'uncaughtException'
event\nhandler.2
- Unused (reserved by Bash for builtin misuse)3
Internal JavaScript Parse Error - The JavaScript source code\ninternal in Node.js's bootstrapping process caused a parse error. This\nis extremely rare, and generally can only happen during development\nof Node.js itself.4
Internal JavaScript Evaluation Failure - The JavaScript\nsource code internal in Node.js's bootstrapping process failed to\nreturn a function value when evaluated. This is extremely rare, and\ngenerally can only happen during development of Node.js itself.5
Fatal Error - There was a fatal unrecoverable error in V8.\nTypically a message will be printed to stderr with the prefix FATAL\nERROR
.6
Non-function Internal Exception Handler - There was an\nuncaught exception, but the internal fatal exception handler\nfunction was somehow set to a non-function, and could not be called.7
Internal Exception Handler Run-Time Failure - There was an\nuncaught exception, and the internal fatal exception handler\nfunction itself threw an error while attempting to handle it. This\ncan happen, for example, if a 'uncaughtException'
or\ndomain.on('error')
handler throws an error.8
- Unused. In previous versions of Node.js, exit code 8 sometimes\nindicated an uncaught exception.9
- Invalid Argument - Either an unknown option was specified,\nor an option requiring a value was provided without a value.10
Internal JavaScript Run-Time Failure - The JavaScript\nsource code internal in Node.js's bootstrapping process threw an error\nwhen the bootstrapping function was called. This is extremely rare,\nand generally can only happen during development of Node.js itself.12
Invalid Debug Argument - The --debug
, --inspect
and/or\n--debug-brk
options were set, but the port number chosen was invalid\nor unavailable.>128
Signal Exits - If Node.js receives a fatal signal such as\nSIGKILL
or SIGHUP
, then its exit code will be 128
plus the\nvalue of the signal code. This is a standard Unix practice, since\nexit codes are defined to be 7-bit integers, and signal exits set\nthe high-order bit, and then contain the value of the signal code.The process.abort()
method causes the Node.js process to exit immediately and\ngenerate a core file.
The process.chdir()
method changes the current working directory of the\nNode.js process or throws an exception if doing so fails (for instance, if\nthe specified directory
does not exist).
console.log(`Starting directory: ${process.cwd()}`);\ntry {\n process.chdir('/tmp');\n console.log(`New directory: ${process.cwd()}`);\n}\ncatch (err) {\n console.log(`chdir: ${err}`);\n}\n
\n"
},
{
"textRaw": "process.cpuUsage([previousValue])",
"type": "method",
"name": "cpuUsage",
"meta": {
"added": [
"v6.1.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Object} ",
"options": [
{
"textRaw": "`user` {integer} ",
"name": "user",
"type": "integer"
},
{
"textRaw": "`system` {integer} ",
"name": "system",
"type": "integer"
}
],
"name": "return",
"type": "Object"
},
"params": [
{
"textRaw": "`previousValue` {Object} A previous return value from calling `process.cpuUsage()` ",
"name": "previousValue",
"type": "Object",
"desc": "A previous return value from calling `process.cpuUsage()`",
"optional": true
}
]
},
{
"params": [
{
"name": "previousValue",
"optional": true
}
]
}
],
"desc": "The process.cpuUsage()
method returns the user and system CPU time usage of\nthe current process, in an object with properties user
and system
, whose\nvalues are microsecond values (millionth of a second). These values measure time\nspent in user and system code respectively, and may end up being greater than\nactual elapsed time if multiple CPU cores are performing work for this process.
The result of a previous call to process.cpuUsage()
can be passed as the\nargument to the function, to get a diff reading.
const startUsage = process.cpuUsage();\n// { user: 38579, system: 6986 }\n\n// spin the CPU for 500 milliseconds\nconst now = Date.now();\nwhile (Date.now() - now < 500);\n\nconsole.log(process.cpuUsage(startUsage));\n// { user: 514883, system: 11226 }\n
\n"
},
{
"textRaw": "process.cwd()",
"type": "method",
"name": "cwd",
"meta": {
"added": [
"v0.1.8"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {string} ",
"name": "return",
"type": "string"
},
"params": []
},
{
"params": []
}
],
"desc": "The process.cwd()
method returns the current working directory of the Node.js\nprocess.
console.log(`Current directory: ${process.cwd()}`);\n
\n"
},
{
"textRaw": "process.disconnect()",
"type": "method",
"name": "disconnect",
"meta": {
"added": [
"v0.7.2"
],
"changes": []
},
"desc": "If the Node.js process is spawned with an IPC channel (see the Child Process\nand Cluster documentation), the process.disconnect()
method will close the\nIPC channel to the parent process, allowing the child process to exit gracefully\nonce there are no other connections keeping it alive.
The effect of calling process.disconnect()
is that same as calling the parent\nprocess's ChildProcess.disconnect()
.
If the Node.js process was not spawned with an IPC channel,\nprocess.disconnect()
will be undefined
.
The process.emitWarning()
method can be used to emit custom or application\nspecific process warnings. These can be listened for by adding a handler to the\nprocess.on('warning')
event.
// Emit a warning using a string...\nprocess.emitWarning('Something happened!');\n// Emits: (node: 56338) Warning: Something happened!\n
\n// Emit a warning using a string and a type...\nprocess.emitWarning('Something Happened!', 'CustomWarning');\n// Emits: (node:56338) CustomWarning: Something Happened!\n
\nprocess.emitWarning('Something happened!', 'CustomWarning', 'WARN001');\n// Emits: (node:56338) CustomWarning [WARN001]: Something Happened!\n
\nIn each of the previous examples, an Error
object is generated internally by\nprocess.emitWarning()
and passed through to the\nprocess.on('warning')
event.
process.on('warning', (warning) => {\n console.warn(warning.name);\n console.warn(warning.message);\n console.warn(warning.code);\n console.warn(warning.stack);\n});\n
\nIf warning
is passed as an Error
object, it will be passed through to the\nprocess.on('warning')
event handler unmodified (and the optional type
,\ncode
and ctor
arguments will be ignored):
// Emit a warning using an Error object...\nconst myWarning = new Error('Warning! Something happened!');\n// Use the Error name property to specify the type name\nmyWarning.name = 'CustomWarning';\nmyWarning.code = 'WARN001';\n\nprocess.emitWarning(myWarning);\n// Emits: (node:56338) CustomWarning [WARN001]: Warning! Something Happened!\n
\nA TypeError
is thrown if warning
is anything other than a string or Error
\nobject.
Note that while process warnings use Error
objects, the process warning\nmechanism is not a replacement for normal error handling mechanisms.
The following additional handling is implemented if the warning type
is\nDeprecationWarning
:
--throw-deprecation
command-line flag is used, the deprecation\nwarning is thrown as an exception rather than being emitted as an event.--no-deprecation
command-line flag is used, the deprecation\nwarning is suppressed.--trace-deprecation
command-line flag is used, the deprecation\nwarning is printed to stderr
along with the full stack trace.As a best practice, warnings should be emitted only once per process. To do\nso, it is recommended to place the emitWarning()
behind a simple boolean\nflag as illustrated in the example below:
function emitMyWarning() {\n if (!emitMyWarning.warned) {\n emitMyWarning.warned = true;\n process.emitWarning('Only warn once!');\n }\n}\nemitMyWarning();\n// Emits: (node: 56339) Warning: Only warn once!\nemitMyWarning();\n// Emits nothing\n
\n",
"type": "module",
"displayName": "Avoiding duplicate warnings"
}
]
},
{
"textRaw": "process.exit([code])",
"type": "method",
"name": "exit",
"meta": {
"added": [
"v0.1.13"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`code` {integer} The exit code. Defaults to `0`. ",
"name": "code",
"type": "integer",
"desc": "The exit code. Defaults to `0`.",
"optional": true
}
]
},
{
"params": [
{
"name": "code",
"optional": true
}
]
}
],
"desc": "The process.exit()
method instructs Node.js to terminate the process\nsynchronously with an exit status of code
. If code
is omitted, exit uses\neither the 'success' code 0
or the value of process.exitCode
if it has been\nset. Node.js will not terminate until all the 'exit'
event listeners are\ncalled.
To exit with a 'failure' code:
\nprocess.exit(1);\n
\nThe shell that executed Node.js should see the exit code as 1
.
It is important to note that calling process.exit()
will force the process to\nexit as quickly as possible even if there are still asynchronous operations\npending that have not yet completed fully, including I/O operations to\nprocess.stdout
and process.stderr
.
In most situations, it is not actually necessary to call process.exit()
\nexplicitly. The Node.js process will exit on its own if there is no additional\nwork pending in the event loop. The process.exitCode
property can be set to\ntell the process which exit code to use when the process exits gracefully.
For instance, the following example illustrates a misuse of the\nprocess.exit()
method that could lead to data printed to stdout being\ntruncated and lost:
// This is an example of what *not* to do:\nif (someConditionNotMet()) {\n printUsageToStdout();\n process.exit(1);\n}\n
\nThe reason this is problematic is because writes to process.stdout
in Node.js\nare sometimes asynchronous and may occur over multiple ticks of the Node.js\nevent loop. Calling process.exit()
, however, forces the process to exit\nbefore those additional writes to stdout
can be performed.
Rather than calling process.exit()
directly, the code should set the\nprocess.exitCode
and allow the process to exit naturally by avoiding\nscheduling any additional work for the event loop:
// How to properly set the exit code while letting\n// the process exit gracefully.\nif (someConditionNotMet()) {\n printUsageToStdout();\n process.exitCode = 1;\n}\n
\nIf it is necessary to terminate the Node.js process due to an error condition,\nthrowing an uncaught error and allowing the process to terminate accordingly\nis safer than calling process.exit()
.
The process.getegid()
method returns the numerical effective group identity\nof the Node.js process. (See getegid(2).)
if (process.getegid) {\n console.log(`Current gid: ${process.getegid()}`);\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows\nor Android)
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "process.geteuid()", "type": "method", "name": "geteuid", "meta": { "added": [ "v2.0.0" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object} ", "name": "return", "type": "Object" }, "params": [] }, { "params": [] } ], "desc": "The process.geteuid()
method returns the numerical effective user identity of\nthe process. (See geteuid(2).)
if (process.geteuid) {\n console.log(`Current uid: ${process.geteuid()}`);\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.getgid()", "type": "method", "name": "getgid", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Object} ", "name": "return", "type": "Object" }, "params": [] }, { "params": [] } ], "desc": "The process.getgid()
method returns the numerical group identity of the\nprocess. (See getgid(2).)
if (process.getgid) {\n console.log(`Current gid: ${process.getgid()}`);\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.getgroups()", "type": "method", "name": "getgroups", "meta": { "added": [ "v0.9.4" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Array} ", "name": "return", "type": "Array" }, "params": [] }, { "params": [] } ], "desc": "The process.getgroups()
method returns an array with the supplementary group\nIDs. POSIX leaves it unspecified if the effective group ID is included but\nNode.js ensures it always is.
Note: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.getuid()", "type": "method", "name": "getuid", "meta": { "added": [ "v0.1.28" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {integer} ", "name": "return", "type": "integer" }, "params": [] }, { "params": [] } ], "desc": "The process.getuid()
method returns the numeric user identity of the process.\n(See getuid(2).)
if (process.getuid) {\n console.log(`Current uid: ${process.getuid()}`);\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.hrtime([time])", "type": "method", "name": "hrtime", "meta": { "added": [ "v0.7.6" ], "changes": [] }, "signatures": [ { "return": { "textRaw": "Returns: {Array} ", "name": "return", "type": "Array" }, "params": [ { "textRaw": "`time` {Array} The result of a previous call to `process.hrtime()` ", "name": "time", "type": "Array", "desc": "The result of a previous call to `process.hrtime()`", "optional": true } ] }, { "params": [ { "name": "time", "optional": true } ] } ], "desc": "The process.hrtime()
method returns the current high-resolution real time\nin a [seconds, nanoseconds]
tuple Array, where nanoseconds
is the\nremaining part of the real time that can't be represented in second precision.
time
is an optional parameter that must be the result of a previous\nprocess.hrtime()
call to diff with the current time. If the parameter\npassed in is not a tuple Array, a TypeError
will be thrown. Passing in a\nuser-defined array instead of the result of a previous call to\nprocess.hrtime()
will lead to undefined behavior.
These times are relative to an arbitrary time in the\npast, and not related to the time of day and therefore not subject to clock\ndrift. The primary use is for measuring performance between intervals:
\nconst NS_PER_SEC = 1e9;\nvar time = process.hrtime();\n// [ 1800216, 25 ]\n\nsetTimeout(() => {\n var diff = process.hrtime(time);\n // [ 1, 552 ]\n\n console.log(`Benchmark took ${diff[0] * NS_PER_SEC + diff[1]} nanoseconds`);\n // benchmark took 1000000552 nanoseconds\n}, 1000);\n
\n"
},
{
"textRaw": "process.initgroups(user, extra_group)",
"type": "method",
"name": "initgroups",
"meta": {
"added": [
"v0.9.4"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`user` {string|number} The user name or numeric identifier. ",
"name": "user",
"type": "string|number",
"desc": "The user name or numeric identifier."
},
{
"textRaw": "`extra_group` {string|number} A group name or numeric identifier. ",
"name": "extra_group",
"type": "string|number",
"desc": "A group name or numeric identifier."
}
]
},
{
"params": [
{
"name": "user"
},
{
"name": "extra_group"
}
]
}
],
"desc": "The process.initgroups()
method reads the /etc/group
file and initializes\nthe group access list, using all groups of which the user is a member. This is\na privileged operation that requires that the Node.js process either have root
\naccess or the CAP_SETGID
capability.
Note that care must be taken when dropping privileges. Example:
\nconsole.log(process.getgroups()); // [ 0 ]\nprocess.initgroups('bnoordhuis', 1000); // switch user\nconsole.log(process.getgroups()); // [ 27, 30, 46, 1000, 0 ]\nprocess.setgid(1000); // drop root gid\nconsole.log(process.getgroups()); // [ 27, 30, 46, 1000 ]\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.kill(pid[, signal])", "type": "method", "name": "kill", "meta": { "added": [ "v0.0.6" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`pid` {number} A process ID ", "name": "pid", "type": "number", "desc": "A process ID" }, { "textRaw": "`signal` {string|number} The signal to send, either as a string or number. Defaults to `'SIGTERM'`. ", "name": "signal", "type": "string|number", "desc": "The signal to send, either as a string or number. Defaults to `'SIGTERM'`.", "optional": true } ] }, { "params": [ { "name": "pid" }, { "name": "signal", "optional": true } ] } ], "desc": "The process.kill()
method sends the signal
to the process identified by\npid
.
Signal names are strings such as 'SIGINT'
or 'SIGHUP'
. See Signal Events\nand kill(2) for more information.
This method will throw an error if the target pid
does not exist. As a special\ncase, a signal of 0
can be used to test for the existence of a process.\nWindows platforms will throw an error if the pid
is used to kill a process\ngroup.
Note:Even though the name of this function is process.kill()
, it is really\njust a signal sender, like the kill
system call. The signal sent may do\nsomething other than kill the target process.
For example:
\nprocess.on('SIGHUP', () => {\n console.log('Got SIGHUP signal.');\n});\n\nsetTimeout(() => {\n console.log('Exiting.');\n process.exit(0);\n}, 100);\n\nprocess.kill(process.pid, 'SIGHUP');\n
\nNote: When SIGUSR1
is received by a Node.js process, Node.js will start the\ndebugger, see Signal Events.
The process.memoryUsage()
method returns an object describing the memory usage\nof the Node.js process measured in bytes.
For example, the code:
\nconsole.log(process.memoryUsage());\n
\nWill generate:
\n{\n rss: 4935680,\n heapTotal: 1826816,\n heapUsed: 650472,\n external: 49879\n}\n
\nheapTotal
and heapUsed
refer to V8's memory usage.\nexternal
refers to the memory usage of C++ objects bound to JavaScript\nobjects managed by V8.
The process.nextTick()
method adds the callback
to the "next tick queue".\nOnce the current turn of the event loop turn runs to completion, all callbacks\ncurrently in the next tick queue will be called.
This is not a simple alias to setTimeout(fn, 0)
. It is much more\nefficient. It runs before any additional I/O events (including\ntimers) fire in subsequent ticks of the event loop.
console.log('start');\nprocess.nextTick(() => {\n console.log('nextTick callback');\n});\nconsole.log('scheduled');\n// Output:\n// start\n// scheduled\n// nextTick callback\n
\nThis is important when developing APIs in order to give users the opportunity\nto assign event handlers after an object has been constructed but before any\nI/O has occurred:
\nfunction MyThing(options) {\n this.setupOptions(options);\n\n process.nextTick(() => {\n this.startDoingStuff();\n });\n}\n\nvar thing = new MyThing();\nthing.getReadyForStuff();\n\n// thing.startDoingStuff() gets called now, not before.\n
\nIt is very important for APIs to be either 100% synchronous or 100%\nasynchronous. Consider this example:
\n// WARNING! DO NOT USE! BAD UNSAFE HAZARD!\nfunction maybeSync(arg, cb) {\n if (arg) {\n cb();\n return;\n }\n\n fs.stat('file', cb);\n}\n
\nThis API is hazardous because in the following case:
\nmaybeSync(true, () => {\n foo();\n});\nbar();\n
\nIt is not clear whether foo()
or bar()
will be called first.
The following approach is much better:
\nfunction definitelyAsync(arg, cb) {\n if (arg) {\n process.nextTick(cb);\n return;\n }\n\n fs.stat('file', cb);\n}\n
\nNote: the next tick queue is completely drained on each pass of the\nevent loop before additional I/O is processed. As a result,\nrecursively setting nextTick callbacks will block any I/O from\nhappening, just like a while(true);
loop.
If Node.js is spawned with an IPC channel, the process.send()
method can be\nused to send messages to the parent process. Messages will be received as a\n'message'
event on the parent's ChildProcess
object.
If Node.js was not spawned with an IPC channel, process.send()
will be\nundefined
.
Note: This function uses JSON.stringify()
internally to serialize the\nmessage
.*
The process.setegid()
method sets the effective group identity of the process.\n(See setegid(2).) The id
can be passed as either a numeric ID or a group\nname string. If a group name is specified, this method blocks while resolving\nthe associated a numeric ID.
if (process.getegid && process.setegid) {\n console.log(`Current gid: ${process.getegid()}`);\n try {\n process.setegid(501);\n console.log(`New gid: ${process.getegid()}`);\n }\n catch (err) {\n console.log(`Failed to set gid: ${err}`);\n }\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.seteuid(id)", "type": "method", "name": "seteuid", "meta": { "added": [ "v2.0.0" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`id` {string|number} A user name or ID ", "name": "id", "type": "string|number", "desc": "A user name or ID" } ] }, { "params": [ { "name": "id" } ] } ], "desc": "The process.seteuid()
method sets the effective user identity of the process.\n(See seteuid(2).) The id
can be passed as either a numeric ID or a username\nstring. If a username is specified, the method blocks while resolving the\nassociated numeric ID.
if (process.geteuid && process.seteuid) {\n console.log(`Current uid: ${process.geteuid()}`);\n try {\n process.seteuid(501);\n console.log(`New uid: ${process.geteuid()}`);\n }\n catch (err) {\n console.log(`Failed to set uid: ${err}`);\n }\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.setgid(id)", "type": "method", "name": "setgid", "meta": { "added": [ "v0.1.31" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`id` {string|number} The group name or ID ", "name": "id", "type": "string|number", "desc": "The group name or ID" } ] }, { "params": [ { "name": "id" } ] } ], "desc": "The process.setgid()
method sets the group identity of the process. (See\nsetgid(2).) The id
can be passed as either a numeric ID or a group name\nstring. If a group name is specified, this method blocks while resolving the\nassociated numeric ID.
if (process.getgid && process.setgid) {\n console.log(`Current gid: ${process.getgid()}`);\n try {\n process.setgid(501);\n console.log(`New gid: ${process.getgid()}`);\n }\n catch (err) {\n console.log(`Failed to set gid: ${err}`);\n }\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.setgroups(groups)", "type": "method", "name": "setgroups", "meta": { "added": [ "v0.9.4" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`groups` {Array} ", "name": "groups", "type": "Array" } ] }, { "params": [ { "name": "groups" } ] } ], "desc": "The process.setgroups()
method sets the supplementary group IDs for the\nNode.js process. This is a privileged operation that requires the Node.js process\nto have root
or the CAP_SETGID
capability.
The groups
array can contain numeric group IDs, group names or both.
Note: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n" }, { "textRaw": "process.setuid(id)", "type": "method", "name": "setuid", "meta": { "added": [ "v0.1.28" ], "changes": [] }, "desc": "The process.setuid(id)
method sets the user identity of the process. (See\nsetuid(2).) The id
can be passed as either a numeric ID or a username string.\nIf a username is specified, the method blocks while resolving the associated\nnumeric ID.
if (process.getuid && process.setuid) {\n console.log(`Current uid: ${process.getuid()}`);\n try {\n process.setuid(501);\n console.log(`New uid: ${process.getuid()}`);\n }\n catch (err) {\n console.log(`Failed to set uid: ${err}`);\n }\n}\n
\nNote: This function is only available on POSIX platforms (i.e. not Windows or\nAndroid)
\n", "signatures": [ { "params": [ { "name": "id" } ] } ] }, { "textRaw": "process.umask([mask])", "type": "method", "name": "umask", "meta": { "added": [ "v0.1.19" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`mask` {number} ", "name": "mask", "type": "number", "optional": true } ] }, { "params": [ { "name": "mask", "optional": true } ] } ], "desc": "The process.umask()
method sets or returns the Node.js process's file mode\ncreation mask. Child processes inherit the mask from the parent process. The old\nmask is return if the mask
argument is given, otherwise returns the current\nmask.
const newmask = 0o022;\nconst oldmask = process.umask(newmask);\nconsole.log(\n `Changed umask from ${oldmask.toString(8)} to ${newmask.toString(8)}`\n);\n
\n"
},
{
"textRaw": "process.uptime()",
"type": "method",
"name": "uptime",
"meta": {
"added": [
"v0.5.0"
],
"changes": []
},
"signatures": [
{
"return": {
"textRaw": "Returns: {number} ",
"name": "return",
"type": "number"
},
"params": []
},
{
"params": []
}
],
"desc": "The process.uptime()
method returns the number of seconds the current Node.js\nprocess has been running.
The process.arch
property returns a String identifying the processor\narchitecture that the Node.js process is currently running on. For instance\n'arm'
, 'ia32'
, or 'x64'
.
console.log(`This processor architecture is ${process.arch}`);\n
\n"
},
{
"textRaw": "`argv` {Array} ",
"type": "Array",
"name": "argv",
"meta": {
"added": [
"v0.1.27"
],
"changes": []
},
"desc": "The process.argv
property returns an array containing the command line\narguments passed when the Node.js process was launched. The first element will\nbe process.execPath
. See process.argv0
if access to the original value of\nargv[0]
is needed. The second element will be the path to the JavaScript\nfile being executed. The remaining elements will be any additional command line\narguments.
For example, assuming the following script for process-args.js
:
// print process.argv\nprocess.argv.forEach((val, index) => {\n console.log(`${index}: ${val}`);\n});\n
\nLaunching the Node.js process as:
\n$ node process-2.js one two=three four\n
\nWould generate the output:
\n0: /usr/local/bin/node\n1: /Users/mjr/work/node/process-2.js\n2: one\n3: two=three\n4: four\n
\n"
},
{
"textRaw": "`argv0` {string} ",
"type": "string",
"name": "argv0",
"meta": {
"added": [
"6.4.0"
],
"changes": []
},
"desc": "The process.argv0
property stores a read-only copy of the original value of\nargv[0]
passed when Node.js starts.
$ bash -c 'exec -a customArgv0 ./node'\n> process.argv[0]\n'/Volumes/code/external/node/out/Release/node'\n> process.argv0\n'customArgv0'\n
\n"
},
{
"textRaw": "process.channel",
"name": "channel",
"meta": {
"added": [
"v7.1.0"
],
"changes": []
},
"desc": "If the Node.js process was spawned with an IPC channel (see the\nChild Process documentation), the process.channel
\nproperty is a reference to the IPC channel. If no IPC channel exists, this\nproperty is undefined
.
The process.config
property returns an Object containing the JavaScript\nrepresentation of the configure options used to compile the current Node.js\nexecutable. This is the same as the config.gypi
file that was produced when\nrunning the ./configure
script.
An example of the possible output looks like:
\n{\n target_defaults:\n { cflags: [],\n default_configuration: 'Release',\n defines: [],\n include_dirs: [],\n libraries: [] },\n variables:\n {\n host_arch: 'x64',\n node_install_npm: 'true',\n node_prefix: '',\n node_shared_cares: 'false',\n node_shared_http_parser: 'false',\n node_shared_libuv: 'false',\n node_shared_zlib: 'false',\n node_use_dtrace: 'false',\n node_use_openssl: 'true',\n node_shared_openssl: 'false',\n strict_aliasing: 'true',\n target_arch: 'x64',\n v8_use_snapshot: 'true'\n }\n}\n
\nNote: The process.config
property is not read-only and there are\nexisting modules in the ecosystem that are known to extend, modify, or entirely\nreplace the value of process.config
.
If the Node.js process is spawned with an IPC channel (see the Child Process\nand Cluster documentation), the process.connected
property will return\ntrue
so long as the IPC channel is connected and will return false
after\nprocess.disconnect()
is called.
Once process.connected
is false
, it is no longer possible to send messages\nover the IPC channel using process.send()
.
The process.env
property returns an object containing the user environment.\nSee environ(7).
An example of this object looks like:
\n{\n TERM: 'xterm-256color',\n SHELL: '/usr/local/bin/bash',\n USER: 'maciej',\n PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',\n PWD: '/Users/maciej',\n EDITOR: 'vim',\n SHLVL: '1',\n HOME: '/Users/maciej',\n LOGNAME: 'maciej',\n _: '/usr/local/bin/node'\n}\n
\nIt is possible to modify this object, but such modifications will not be\nreflected outside the Node.js process. In other words, the following example\nwould not work:
\n$ node -e 'process.env.foo = "bar"' && echo $foo\n
\nWhile the following will:
\nprocess.env.foo = 'bar';\nconsole.log(process.env.foo);\n
\nAssigning a property on process.env
will implicitly convert the value\nto a string.
Example:
\nprocess.env.test = null;\nconsole.log(process.env.test);\n// => 'null'\nprocess.env.test = undefined;\nconsole.log(process.env.test);\n// => 'undefined'\n
\nUse delete
to delete a property from process.env
.
Example:
\nprocess.env.TEST = 1;\ndelete process.env.TEST;\nconsole.log(process.env.TEST);\n// => undefined\n
\nOn Windows operating systems, environment variables are case-insensitive.
\nExample:
\nprocess.env.TEST = 1;\nconsole.log(process.env.test);\n// => 1\n
\n"
},
{
"textRaw": "`execArgv` {Object} ",
"type": "Object",
"name": "execArgv",
"meta": {
"added": [
"v0.7.7"
],
"changes": []
},
"desc": "The process.execArgv
property returns the set of Node.js-specific command-line\noptions passed when the Node.js process was launched. These options do not\nappear in the array returned by the process.argv
property, and do not\ninclude the Node.js executable, the name of the script, or any options following\nthe script name. These options are useful in order to spawn child processes with\nthe same execution environment as the parent.
For example:
\n$ node --harmony script.js --version\n
\nResults in process.execArgv
:
['--harmony']\n
\nAnd process.argv
:
['/usr/local/bin/node', 'script.js', '--version']\n
\n"
},
{
"textRaw": "`execPath` {string} ",
"type": "string",
"name": "execPath",
"meta": {
"added": [
"v0.1.100"
],
"changes": []
},
"desc": "The process.execPath
property returns the absolute pathname of the executable\nthat started the Node.js process.
For example:
\n'/usr/local/bin/node'\n
\n"
},
{
"textRaw": "`exitCode` {integer} ",
"type": "integer",
"name": "exitCode",
"meta": {
"added": [
"v0.11.8"
],
"changes": []
},
"desc": "A number which will be the process exit code, when the process either\nexits gracefully, or is exited via process.exit()
without specifying\na code.
Specifying a code to process.exit(code)
will override any\nprevious setting of process.exitCode
.
The process.mainModule
property provides an alternative way of retrieving\nrequire.main
. The difference is that if the main module changes at\nruntime, require.main
may still refer to the original main module in\nmodules that were required before the change occurred. Generally, it's\nsafe to assume that the two refer to the same module.
As with require.main
, process.mainModule
will be undefined
if there\nis no entry script.
The process.pid
property returns the PID of the process.
console.log(`This process is pid ${process.pid}`);\n
\n"
},
{
"textRaw": "`platform` {string} ",
"type": "string",
"name": "platform",
"meta": {
"added": [
"v0.1.16"
],
"changes": []
},
"desc": "The process.platform
property returns a string identifying the operating\nsystem platform on which the Node.js process is running. For instance\n'darwin'
, 'freebsd'
, 'linux'
, 'sunos'
or 'win32'
console.log(`This platform is ${process.platform}`);\n
\n"
},
{
"textRaw": "process.release",
"name": "release",
"meta": {
"added": [
"v3.0.0"
],
"changes": [
{
"version": "v4.2.0",
"pr-url": "https://github.com/nodejs/node/pull/3212",
"description": "The `lts` property is now supported."
}
]
},
"desc": "The process.release
property returns an Object containing metadata related to\nthe current release, including URLs for the source tarball and headers-only\ntarball.
process.release
contains the following properties:
name
{string} A value that will always be 'node'
for Node.js. For\nlegacy io.js releases, this will be 'io.js'
.sourceUrl
{string} an absolute URL pointing to a .tar.gz
file containing\nthe source code of the current release.headersUrl
{string} an absolute URL pointing to a .tar.gz
file containing\nonly the source header files for the current release. This file is\nsignificantly smaller than the full source file and can be used for compiling\nNode.js native add-ons.libUrl
{string} an absolute URL pointing to a node.lib
file matching the\narchitecture and version of the current release. This file is used for\ncompiling Node.js native add-ons. This property is only present on Windows\nbuilds of Node.js and will be missing on all other platforms.lts
{string} a string label identifying the LTS label for this release.\nIf the Node.js release is not an LTS release, this will be undefined
.For example:
\n{\n name: 'node',\n lts: 'Argon',\n sourceUrl: 'https://nodejs.org/download/release/v4.4.5/node-v4.4.5.tar.gz',\n headersUrl: 'https://nodejs.org/download/release/v4.4.5/node-v4.4.5-headers.tar.gz',\n libUrl: 'https://nodejs.org/download/release/v4.4.5/win-x64/node.lib'\n}\n
\nIn custom builds from non-release versions of the source tree, only the\nname
property may be present. The additional properties should not be\nrelied upon to exist.
The process.stderr
property returns a stream connected to\nstderr
(fd 2
). It is a net.Socket
(which is a Duplex\nstream) unless fd 2
refers to a file, in which case it is\na Writable stream.
Note: process.stderr
differs from other Node.js streams in important ways,\nsee note on process I/O for more information.
The process.stdin
property returns a stream connected to\nstdin
(fd 0
). It is a net.Socket
(which is a Duplex\nstream) unless fd 0
refers to a file, in which case it is\na Readable stream.
For example:
\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('readable', () => {\n var chunk = process.stdin.read();\n if (chunk !== null) {\n process.stdout.write(`data: ${chunk}`);\n }\n});\n\nprocess.stdin.on('end', () => {\n process.stdout.write('end');\n});\n
\nAs a Duplex stream, process.stdin
can also be used in "old" mode that\nis compatible with scripts written for Node.js prior to v0.10.\nFor more information see Stream compatibility.
Note: In "old" streams mode the stdin
stream is paused by default, so one\nmust call process.stdin.resume()
to read from it. Note also that calling\nprocess.stdin.resume()
itself would switch stream to "old" mode.
The process.stdout
property returns a stream connected to\nstdout
(fd 1
). It is a net.Socket
(which is a Duplex\nstream) unless fd 1
refers to a file, in which case it is\na Writable stream.
For example, to copy process.stdin to process.stdout:
\nprocess.stdin.pipe(process.stdout);\n
\nNote: process.stdout
differs from other Node.js streams in important ways,\nsee note on process I/O for more information.
process.stdout
and process.stderr
differ from other Node.js streams in\nimportant ways:
console.log()
and console.error()
,\nrespectively.end()
will throw).'finish'
event.These behaviours are partly for historical reasons, as changing them would\ncreate backwards incompatibility, but they are also expected by some users.
\nSynchronous writes avoid problems such as output written with console.log()
or\nconsole.write()
being unexpectedly interleaved, or not written at all if\nprocess.exit()
is called before an asynchronous write completes. See\nprocess.exit()
for more information.
Warning: Synchronous writes block the event loop until the write has\ncompleted. This can be near instantaneous in the case of output to a file, but\nunder high system load, pipes that are not being read at the receiving end, or\nwith slow terminals or file systems, its possible for the event loop to be\nblocked often enough and long enough to have severe negative performance\nimpacts. This may not be a problem when writing to an interactive terminal\nsession, but consider this particularly careful when doing production logging to\nthe process output streams.
\nTo check if a stream is connected to a TTY context, check the isTTY
\nproperty.
For instance:
\n$ node -p "Boolean(process.stdin.isTTY)"\ntrue\n$ echo "foo" | node -p "Boolean(process.stdin.isTTY)"\nfalse\n$ node -p "Boolean(process.stdout.isTTY)"\ntrue\n$ node -p "Boolean(process.stdout.isTTY)" | cat\nfalse\n
\nSee the TTY documentation for more information.
\n", "type": "module", "displayName": "A note on process I/O" } ] }, { "textRaw": "`title` {string} ", "type": "string", "name": "title", "meta": { "added": [ "v0.1.104" ], "changes": [] }, "desc": "The process.title
property returns the current process title (i.e. returns\nthe current value of ps
). Assigning a new value to process.title
modifies\nthe current value of ps
.
Note: When a new value is assigned, different platforms will impose different\nmaximum length restrictions on the title. Usually such restrictions are quite\nlimited. For instance, on Linux and OS X, process.title
is limited to the size\nof the binary name plus the length of the command line arguments because setting\nthe process.title
overwrites the argv
memory of the process. Node.js v0.8\nallowed for longer process title strings by also overwriting the environ
\nmemory but that was potentially insecure and confusing in some (rather obscure)\ncases.
The process.version
property returns the Node.js version string.
console.log(`Version: ${process.version}`);\n
\n"
},
{
"textRaw": "`versions` {Object} ",
"type": "Object",
"name": "versions",
"meta": {
"added": [
"v0.2.0"
],
"changes": [
{
"version": "v4.2.0",
"pr-url": "https://github.com/nodejs/node/pull/3102",
"description": "The `icu` property is now supported."
}
]
},
"desc": "The process.versions
property returns an object listing the version strings of\nNode.js and its dependencies. process.versions.modules
indicates the current\nABI version, which is increased whenever a C++ API changes. Node.js will refuse\nto load modules that were compiled against a different module ABI version.
console.log(process.versions);\n
\nWill generate output similar to:
\n{\n http_parser: '2.3.0',\n node: '1.1.1',\n v8: '4.1.0.14',\n uv: '1.3.0',\n zlib: '1.2.8',\n ares: '1.10.0-DEV',\n modules: '43',\n icu: '55.1',\n openssl: '1.0.1k',\n unicode: '8.0',\n cldr: '29.0',\n tz: '2016b' }\n
\n"
}
]
}
]
}