{ "source": "doc/api/process.markdown", "globals": [ { "textRaw": "process", "name": "process", "type": "global", "desc": "
The process
object is a global object and can be accessed from anywhere.\nIt is an instance of [EventEmitter][].\n\n
This event is emitted when Node.js empties its event loop and has nothing else to\nschedule. Normally, Node.js exits when there is no work scheduled, but a listener\nfor 'beforeExit' can make asynchronous calls, and cause Node.js to continue.\n\n
\n'beforeExit' is not emitted for conditions causing explicit termination, such as\nprocess.exit()
or uncaught exceptions, and should not be used as an\nalternative to the 'exit' event unless the intention is to schedule more work.\n\n
Emitted when the process is about to exit. There is no way to prevent the\nexiting of the event loop at this point, and once all exit
listeners have\nfinished running the process will exit. Therefore you must only perform\nsynchronous operations in this handler. This is a good hook to perform\nchecks on the module's state (like for unit tests). The callback takes one\nargument, the code the process is exiting with.\n\n
This event is only emitted when Node.js exits explicitly by process.exit() or\nimplicitly by the event loop draining.\n\n
\nExample of listening for exit
:\n\n
process.on('exit', function(code) {\n // do *NOT* do this\n setTimeout(function() {\n console.log('This will not run');\n }, 0);\n console.log('About to exit with code:', code);\n});
\n",
"params": []
},
{
"textRaw": "Event: 'message'",
"type": "event",
"name": "message",
"params": [],
"desc": "Messages sent by [ChildProcess.send()][] are obtained using the 'message'
\nevent on the child's process object.\n\n
Emitted whenever a Promise was rejected and an error handler was attached to it\n(for example with .catch()
) later than after an event loop turn. This event\nis emitted with the following arguments:\n\n
p
the promise that was previously emitted in an 'unhandledRejection'
\nevent, but which has now gained a rejection 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 rejection\ncan be be handled at a future point in time — possibly much later than the\nevent loop turn it takes for the 'unhandledRejection'
event to be emitted.\n\n
Another way of stating this is that, unlike in synchronous code where there is\nan ever-growing list of unhandled exceptions, with promises there is a\ngrowing-and-shrinking list of unhandled rejections. In synchronous code, the\n'uncaughtException' event tells you when the list of unhandled exceptions\ngrows. And in asynchronous code, the 'unhandledRejection'
event tells you\nwhen the list of unhandled rejections grows, while the 'rejectionHandled'\nevent tells you when the list of unhandled rejections shrinks.\n\n
For example using the rejection detection hooks in order to keep a map of all\nthe rejected promise reasons at a given time:\n\n
\nvar unhandledRejections = new Map();\nprocess.on('unhandledRejection', function(reason, p) {\n unhandledRejections.set(p, reason);\n});\nprocess.on('rejectionHandled', function(p) {\n unhandledRejections.delete(p);\n});
\nThis map will grow and shrink over time, reflecting rejections that start\nunhandled and then become handled. You could record the errors in some error\nlog, either periodically (probably best for long-running programs, allowing\nyou to clear the map, which in the case of a very buggy program could grow\nindefinitely) or upon process exit (more convenient for scripts).\n\n
\n", "params": [] }, { "textRaw": "Event: 'uncaughtException'", "type": "event", "name": "uncaughtException", "desc": "Emitted when an exception bubbles all the way back to the event loop. If a\nlistener is added for this exception, the default action (which is to print\na stack trace and exit) will not occur.\n\n
\nExample of listening for uncaughtException
:\n\n
process.on('uncaughtException', function(err) {\n console.log('Caught exception: ' + err);\n});\n\nsetTimeout(function() {\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.');
\nNote that uncaughtException
is a very crude mechanism for exception\nhandling.\n\n
Do not use it as the Node.js equivalent of On Error Resume Next
. An\nunhandled exception means your application - and by extension Node.js itself -\nis in an undefined state. Blindly resuming means anything could happen.\n\n
Think of resuming as pulling the power cord when you are upgrading your system.\nNine out of ten times nothing happens - but the 10th time, your system is bust.\n\n
\nuncaughtException
should be used to perform synchronous cleanup before\nshutting down the process. It is not safe to resume normal operation after\nuncaughtException
. If you do use it, restart your application after every\nunhandled exception!\n\n
You have been warned.\n\n
\n", "params": [] }, { "textRaw": "Event: 'unhandledRejection'", "type": "event", "name": "unhandledRejection", "desc": "Emitted whenever a Promise
is rejected and no error handler is attached to\nthe promise within a turn of the event loop. When programming with promises\nexceptions are encapsulated as rejected promises. Such promises can be caught\nand handled using promise.catch(...)
and rejections are propagated through\na promise chain. This event is useful for detecting and keeping track of\npromises that were rejected whose rejections were not handled yet. This event\nis emitted with the following arguments:\n\n
reason
the object with which the promise was rejected (usually an Error
\ninstance).p
the promise that was rejected.Here is an example that logs every unhandled rejection to the console\n\n
\nprocess.on('unhandledRejection', function(reason, p) {\n console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);\n // application specific logging, throwing an error, or other logic here\n});
\nFor example, here is a rejection that will trigger the 'unhandledRejection'
\nevent:\n\n
somePromise.then(function(res) {\n return reportToUser(JSON.pasre(res)); // note the typo\n}); // no `.catch` or `.then`
\nHere is an example of a coding pattern that will also trigger\n'unhandledRejection'
:\n\n
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
\nIn cases like this, you may not want to track the rejection as a developer\nerror like you would for other 'unhandledRejection'
events. To address\nthis, you can either attach a dummy .catch(function() { })
handler to\nresource.loaded
, preventing the 'unhandledRejection'
event from being\nemitted, or you can use the 'rejectionHandled'
event. Below is an\nexplanation of how to do that.\n\n
Emitted when the processes receives a signal. See sigaction(2) for a list of\nstandard POSIX signal names such as SIGINT, SIGHUP, etc.\n\n
\nExample of listening for SIGINT
:\n\n
// Start reading from stdin so we don't exit.\nprocess.stdin.resume();\n\nprocess.on('SIGINT', function() {\n console.log('Got SIGINT. Press Control-D to exit.');\n});
\nAn easy way to send the SIGINT
signal is with Control-C
in most terminal\nprograms.\n\n
Note:\n\n
\nSIGUSR1
is reserved by Node.js to start the debugger. It's possible to\ninstall a listener but that won't stop the debugger from starting.SIGTERM
and SIGINT
have default handlers on non-Windows platforms that resets\nthe terminal mode before exiting with code 128 + signal number
. If one of\nthese signals has a listener installed, its default behavior will be removed\n(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 other\nplatforms 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 non-Windows\nplatforms it can be listened on, but there is no way to send or generate it.SIGWINCH
is delivered when the console has been resized. On Windows, this will\nonly happen on write to the console when the cursor is being moved, or when a\nreadable 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.Note that Windows does not support sending Signals, but Node.js offers some\nemulation with process.kill()
, and child_process.kill()
. Sending signal 0
\ncan be used to test for the existence of a process. Sending SIGINT
,\nSIGTERM
, and SIGKILL
cause the unconditional termination of the target\nprocess.\n\n
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:\n\n
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 process.on('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
and/or --debug-brk
\noptions were set, but an invalid port number was chosen.>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.This causes Node.js to emit an abort. This will cause Node.js to exit and\ngenerate a core file.\n\n
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "process.chdir(directory)", "type": "method", "name": "chdir", "desc": "Changes the current working directory of the process or throws an exception if that fails.\n\n
\nconsole.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",
"signatures": [
{
"params": [
{
"name": "directory"
}
]
}
]
},
{
"textRaw": "process.cwd()",
"type": "method",
"name": "cwd",
"desc": "Returns the current working directory of the process.\n\n
\nconsole.log('Current directory: ' + process.cwd());\n\n
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "process.disconnect()", "type": "method", "name": "disconnect", "desc": "Close the IPC channel to the parent process, allowing this child to exit\ngracefully once there are no other connections keeping it alive.\n\n
\nIdentical to the parent process's [ChildProcess.disconnect()][].\n\n
\nIf Node.js was not spawned with an IPC channel, process.disconnect()
will be\nundefined.\n\n
Ends the process with the specified code
. If omitted, exit uses the\n'success' code 0
.\n\n
To exit with a 'failure' code:\n\n
\nprocess.exit(1);
\nThe shell that executed Node.js should see the exit code as 1.\n\n\n
\n", "signatures": [ { "params": [ { "name": "code", "optional": true } ] } ] }, { "textRaw": "process.getegid()", "type": "method", "name": "getegid", "desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nGets the effective group identity of the process. (See getegid(2).)\nThis is the numerical group id, not the group name.\n\n
\nif (process.getegid) {\n console.log('Current gid: ' + process.getegid());\n}
\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "process.geteuid()",
"type": "method",
"name": "geteuid",
"desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nGets the effective user identity of the process. (See geteuid(2).)\nThis is the numerical userid, not the username.\n\n
\nif (process.geteuid) {\n console.log('Current uid: ' + process.geteuid());\n}
\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "process.getgid()",
"type": "method",
"name": "getgid",
"desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nGets the group identity of the process. (See getgid(2).)\nThis is the numerical group id, not the group name.\n\n
\nif (process.getgid) {\n console.log('Current gid: ' + process.getgid());\n}
\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "process.getgroups()",
"type": "method",
"name": "getgroups",
"desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nReturns an array with the supplementary group IDs. POSIX leaves it unspecified\nif the effective group ID is included but Node.js ensures it always is.\n\n
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "process.getuid()", "type": "method", "name": "getuid", "desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nGets the user identity of the process. (See getuid(2).)\nThis is the numerical userid, not the username.\n\n
\nif (process.getuid) {\n console.log('Current uid: ' + process.getuid());\n}
\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "process.hrtime()",
"type": "method",
"name": "hrtime",
"desc": "Returns the current high-resolution real time in a [seconds, nanoseconds]
\ntuple Array. It is relative to an arbitrary time in the past. It is not\nrelated to the time of day and therefore not subject to clock drift. The\nprimary use is for measuring performance between intervals.\n\n
You may pass in the result of a previous call to process.hrtime()
to get\na diff reading, useful for benchmarks and measuring intervals:\n\n
var time = process.hrtime();\n// [ 1800216, 25 ]\n\nsetTimeout(function() {\n var diff = process.hrtime(time);\n // [ 1, 552 ]\n\n console.log('benchmark took %d nanoseconds', diff[0] * 1e9 + diff[1]);\n // benchmark took 1000000527 nanoseconds\n}, 1000);
\n",
"signatures": [
{
"params": []
}
]
},
{
"textRaw": "process.initgroups(user, extra_group)",
"type": "method",
"name": "initgroups",
"desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nReads /etc/group and initializes the group access list, using all groups of\nwhich the user is a member. This is a privileged operation, meaning you need\nto be root or have the CAP_SETGID capability.\n\n
\nuser
is a user name or user ID. extra_group
is a group name or group ID.\n\n
Some care needs to be taken when dropping privileges. Example:\n\n
\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",
"signatures": [
{
"params": [
{
"name": "user"
},
{
"name": "extra_group"
}
]
}
]
},
{
"textRaw": "process.kill(pid[, signal])",
"type": "method",
"name": "kill",
"desc": "Send a signal to a process. pid
is the process id and signal
is the\nstring describing the signal to send. Signal names are strings like\n'SIGINT' or 'SIGHUP'. If omitted, the signal will be 'SIGTERM'.\nSee [Signal Events][] and kill(2) for more information.\n\n
Will throw an error if target does not exist, and as a special case, a signal\nof 0
can be used to test for the existence of a process.\n\n
Note that 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.\n\n
Example of sending a signal to yourself:\n\n
\nprocess.on('SIGHUP', function() {\n console.log('Got SIGHUP signal.');\n});\n\nsetTimeout(function() {\n console.log('Exiting.');\n process.exit(0);\n}, 100);\n\nprocess.kill(process.pid, 'SIGHUP');
\nNote: When SIGUSR1 is received by Node.js it starts the debugger, see\n[Signal Events][].\n\n
\n", "signatures": [ { "params": [ { "name": "pid" }, { "name": "signal", "optional": true } ] } ] }, { "textRaw": "process.memoryUsage()", "type": "method", "name": "memoryUsage", "desc": "Returns an object describing the memory usage of the Node.js process\nmeasured in bytes.\n\n
\nvar util = require('util');\n\nconsole.log(util.inspect(process.memoryUsage()));
\nThis will generate:\n\n
\n{ rss: 4935680,\n heapTotal: 1826816,\n heapUsed: 650472 }
\nheapTotal
and heapUsed
refer to V8's memory usage.\n\n\n
Once the current event loop turn runs to completion, call the callback\nfunction.\n\n
\nThis is not a simple alias to setTimeout(fn, 0)
, it's much more\nefficient. It runs before any additional I/O events (including\ntimers) fire in subsequent ticks of the event loop.\n\n
console.log('start');\nprocess.nextTick(function() {\n console.log('nextTick callback');\n});\nconsole.log('scheduled');\n// Output:\n// start\n// scheduled\n// nextTick callback
\nThis is important in developing APIs where you want to give the user the\nchance to assign event handlers after an object has been constructed,\nbut before any I/O has occurred.\n\n
\nfunction MyThing(options) {\n this.setupOptions(options);\n\n process.nextTick(function() {\n this.startDoingStuff();\n }.bind(this));\n}\n\nvar thing = new MyThing();\nthing.getReadyForStuff();\n\n// thing.startDoingStuff() gets called now, not before.
\nIt is very important for APIs to be either 100% synchronous or 100%\nasynchronous. Consider this example:\n\n
\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}
\nThis API is hazardous. If you do this:\n\n
\nmaybeSync(true, function() {\n foo();\n});\nbar();
\nthen it's not clear whether foo()
or bar()
will be called first.\n\n
This approach is much better:\n\n
\nfunction definitelyAsync(arg, cb) {\n if (arg) {\n process.nextTick(cb);\n return;\n }\n\n fs.stat('file', cb);\n}
\nNote: the nextTick 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.\n\n
When Node.js is spawned with an IPC channel attached, it can send messages to its\nparent process using process.send()
. Each will be received as a\n['message'][] event on the parent's ChildProcess
object.\n\n
If Node.js was not spawned with an IPC channel, process.send()
will be undefined.\n\n
Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nSets the effective group identity of the process. (See setegid(2).)\nThis accepts either a numerical ID or a groupname string. If a groupname\nis specified, this method blocks while resolving it to a numerical ID.\n\n
\nif (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",
"signatures": [
{
"params": [
{
"name": "id"
}
]
}
]
},
{
"textRaw": "process.seteuid(id)",
"type": "method",
"name": "seteuid",
"desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nSets the effective user identity of the process. (See seteuid(2).)\nThis accepts either a numerical ID or a username string. If a username\nis specified, this method blocks while resolving it to a numerical ID.\n\n
\nif (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",
"signatures": [
{
"params": [
{
"name": "id"
}
]
}
]
},
{
"textRaw": "process.setgid(id)",
"type": "method",
"name": "setgid",
"desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nSets the group identity of the process. (See setgid(2).) This accepts either\na numerical ID or a groupname string. If a groupname is specified, this method\nblocks while resolving it to a numerical ID.\n\n
\nif (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",
"signatures": [
{
"params": [
{
"name": "id"
}
]
}
]
},
{
"textRaw": "process.setgroups(groups)",
"type": "method",
"name": "setgroups",
"desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nSets the supplementary group IDs. This is a privileged operation, meaning you\nneed to be root or have the CAP_SETGID capability.\n\n
\nThe list can contain group IDs, group names or both.\n\n
\n", "signatures": [ { "params": [ { "name": "groups" } ] } ] }, { "textRaw": "process.setuid(id)", "type": "method", "name": "setuid", "desc": "Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n
\nSets the user identity of the process. (See setuid(2).) This accepts either\na numerical ID or a username string. If a username is specified, this method\nblocks while resolving it to a numerical ID.\n\n
\nif (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",
"signatures": [
{
"params": [
{
"name": "id"
}
]
}
]
},
{
"textRaw": "process.umask([mask])",
"type": "method",
"name": "umask",
"desc": "Sets or reads the process's file mode creation mask. Child processes inherit\nthe mask from the parent process. Returns the old mask if mask
argument is\ngiven, otherwise returns the current mask.\n\n
var oldmask, newmask = 0022;\n\noldmask = process.umask(newmask);\nconsole.log('Changed umask from: ' + oldmask.toString(8) +\n ' to ' + newmask.toString(8));
\n",
"signatures": [
{
"params": [
{
"name": "mask",
"optional": true
}
]
}
]
},
{
"textRaw": "process.uptime()",
"type": "method",
"name": "uptime",
"desc": "Number of seconds Node.js has been running.\n\n
\n", "signatures": [ { "params": [] } ] } ], "properties": [ { "textRaw": "process.arch", "name": "arch", "desc": "What processor architecture you're running on: 'arm'
, 'ia32'
, or 'x64'
.\n\n
console.log('This processor architecture is ' + process.arch);
\n"
},
{
"textRaw": "process.argv",
"name": "argv",
"desc": "An array containing the command line arguments. The first element will be\n'node', the second element will be the name of the JavaScript file. The\nnext elements will be any additional command line arguments.\n\n
\n// print process.argv\nprocess.argv.forEach(function(val, index, array) {\n console.log(index + ': ' + val);\n});
\nThis will generate:\n\n
\n$ node process-2.js one two=three four\n0: node\n1: /Users/mjr/work/node/process-2.js\n2: one\n3: two=three\n4: four
\n"
},
{
"textRaw": "process.config",
"name": "config",
"desc": "An Object containing the JavaScript representation of the configure options\nthat were used to compile the current Node.js executable. This is the same as\nthe "config.gypi" file that was produced when running the ./configure
script.\n\n
An example of the possible output looks like:\n\n
\n{ target_defaults:\n { cflags: [],\n default_configuration: 'Release',\n defines: [],\n include_dirs: [],\n libraries: [] },\n variables:\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",
"properties": [
{
"textRaw": "`connected` {Boolean} Set to false after `process.disconnect()` is called ",
"name": "connected",
"desc": "If process.connected
is false, it is no longer possible to send messages.\n\n
An object containing the user environment. See environ(7).\n\n
\nAn example of this object looks like:\n\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' }
\nYou can write to this object, but changes won't be reflected outside of your\nprocess. That means that the following won't work:\n\n
\n$ node -e 'process.env.foo = "bar"' && echo $foo
\nBut this will:\n\n
\nprocess.env.foo = 'bar';\nconsole.log(process.env.foo);
\n"
},
{
"textRaw": "process.execArgv",
"name": "execArgv",
"desc": "This is the set of Node.js-specific command line options from the\nexecutable that started the process. These options do not show up in\nprocess.argv
, and do not include the Node.js executable, the name of\nthe script, or any options following the script name. These options\nare useful in order to spawn child processes with the same execution\nenvironment as the parent.\n\n
Example:\n\n
\n$ node --harmony script.js --version
\nresults in process.execArgv:\n\n
\n['--harmony']
\nand process.argv:\n\n
\n['/usr/local/bin/node', 'script.js', '--version']
\n"
},
{
"textRaw": "process.execPath",
"name": "execPath",
"desc": "This is the absolute pathname of the executable that started the process.\n\n
\nExample:\n\n
\n/usr/local/bin/node
\n"
},
{
"textRaw": "process.exitCode",
"name": "exitCode",
"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.\n\n
Specifying a code to process.exit(code)
will override any previous\nsetting of process.exitCode
.\n\n\n
Alternate way to retrieve [require.main
][]. The difference is that if the main\nmodule changes at runtime, require.main
might still refer to the original main\nmodule in modules that were required before the change occurred. Generally it's\nsafe to assume that the two refer to the same module.\n\n
As with require.main
, it will be undefined
if there was no entry script.\n\n
The PID of the process.\n\n
\nconsole.log('This process is pid ' + process.pid);
\n"
},
{
"textRaw": "process.platform",
"name": "platform",
"desc": "What platform you're running on:\n'darwin'
, 'freebsd'
, 'linux'
, 'sunos'
or 'win32'
\n\n
console.log('This platform is ' + process.platform);
\n"
},
{
"textRaw": "process.release",
"name": "release",
"desc": "An Object containing metadata related to the current release, including URLs\nfor the source tarball and headers-only tarball.\n\n
\nprocess.release
contains the following properties:\n\n
name
: a string with a value that will always be "node"
for Node.js. For\nlegacy io.js releases, this will be "io.js"
.sourceUrl
: a complete URL pointing to a .tar.gz file containing the\nsource of the current release.headersUrl
: a complete URL pointing to a .tar.gz file containing only\nthe header files for the current release. This file is significantly smaller\nthan the full source file and can be used for compiling add-ons against\nNode.js.libUrl
: a complete URL pointing to an node.lib file matching the\narchitecture and version of the current release. This file is used for\ncompiling add-ons against Node.js. This property is only present on Windows\nbuilds of Node.js and will be missing on all other platforms.e.g.\n\n
\n{ name: 'node',\n sourceUrl: 'https://nodejs.org/download/release/v4.0.0/node-v4.0.0.tar.gz',\n headersUrl: 'https://nodejs.org/download/release/v4.0.0/node-v4.0.0-headers.tar.gz',\n libUrl: 'https://nodejs.org/download/release/v4.0.0/win-x64/node.lib' }
\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.\n\n
A writable stream to stderr (on fd 2
).\n\n
process.stderr
and process.stdout
are unlike other streams in Node.js in\nthat they cannot be closed (end()
will throw), they never emit the finish
\nevent and that writes can block when output is redirected to a file (although\ndisks are fast and operating systems normally employ write-back caching so it\nshould be a very rare occurrence indeed.)\n\n
A Readable Stream
for stdin (on fd 0
).\n\n
Example of opening standard input and listening for both events:\n\n
\nprocess.stdin.setEncoding('utf8');\n\nprocess.stdin.on('readable', function() {\n var chunk = process.stdin.read();\n if (chunk !== null) {\n process.stdout.write('data: ' + chunk);\n }\n});\n\nprocess.stdin.on('end', function() {\n process.stdout.write('end');\n});
\nAs a Stream, process.stdin
can also be used in "old" mode that is compatible\nwith scripts written for node.js prior to v0.10.\nFor more information see [Stream compatibility][].\n\n
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.\n\n
If you are starting a new project you should prefer a more recent "new" Streams\nmode over "old" one.\n\n
\n" }, { "textRaw": "process.stdout", "name": "stdout", "desc": "A Writable Stream
to stdout
(on fd 1
).\n\n
For example, a console.log
equivalent could look like this:\n\n
console.log = function(msg) {\n process.stdout.write(msg + '\\n');\n};
\nprocess.stderr
and process.stdout
are unlike other streams in Node.js in\nthat they cannot be closed (end()
will throw), they never emit the finish
\nevent and that writes can block when output is redirected to a file (although\ndisks are fast and operating systems normally employ write-back caching so it\nshould be a very rare occurrence indeed.)\n\n
To check if Node.js is being run in a TTY context, read the isTTY
property\non process.stderr
, process.stdout
, or process.stdin
:\n\n
$ node -p "Boolean(process.stdin.isTTY)"\ntrue\n$ echo "foo" | node -p "Boolean(process.stdin.isTTY)"\nfalse\n\n$ node -p "Boolean(process.stdout.isTTY)"\ntrue\n$ node -p "Boolean(process.stdout.isTTY)" | cat\nfalse
\nSee [the tty docs][] for more information.\n\n
\n" }, { "textRaw": "process.title", "name": "title", "desc": "Getter/setter to set what is displayed in 'ps'.\n\n
\nWhen used as a setter, the maximum length is platform-specific and probably\nshort.\n\n
\nOn Linux and OS X, it's limited to the size of the binary name plus the\nlength of the command line arguments because it overwrites the argv memory.\n\n
\nv0.8 allowed for longer process title strings by also overwriting the environ\nmemory but that was potentially insecure/confusing in some (rather obscure)\ncases.\n\n
\n" }, { "textRaw": "process.version", "name": "version", "desc": "A compiled-in property that exposes NODE_VERSION
.\n\n
console.log('Version: ' + process.version);
\n"
},
{
"textRaw": "process.versions",
"name": "versions",
"desc": "A property exposing version strings of Node.js and its dependencies.\n\n
\nconsole.log(process.versions);
\nWill print something like:\n\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"
}
]
}
]
}