{ "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

\n", "modules": [ { "textRaw": "Exit Codes", "name": "exit_codes", "desc": "

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

\n\n", "type": "module", "displayName": "Exit Codes" } ], "events": [ { "textRaw": "Event: 'exit'", "type": "event", "name": "exit", "desc": "

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

\n

This event is only emitted when node exits explicitly by process.exit() or\nimplicitly by the event loop draining.\n\n

\n

Example of listening for exit:\n\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\n

\n" }, { "textRaw": "Event: 'beforeExit'", "type": "event", "name": "beforeExit", "desc": "

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\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

\n

Example of listening for uncaughtException:\n\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.');
\n

Note that uncaughtException is a very crude mechanism for exception\nhandling.\n\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

\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

\n

uncaughtException 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

\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

\n\n

Here is an example that logs every unhandled rejection to the console\n\n

\n
process.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});
\n

For example, here is a rejection that will trigger the 'unhandledRejection'\nevent:\n\n

\n
somePromise.then(function(res) {\n  return reportToUser(JSON.pasre(res)); // note the typo\n}); // no `.catch` or `.then`
\n

Here is an example of a coding pattern that will also trigger\n'unhandledRejection':\n\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
\n

In 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

\n", "params": [] }, { "textRaw": "Event: 'rejectionHandled'", "type": "event", "name": "rejectionHandled", "desc": "

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

\n\n

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

\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

\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

\n
var 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});
\n

This 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": "Signal Events", "name": "SIGINT, SIGHUP, etc.", "type": "event", "desc": "

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

\n

Example of listening for SIGINT:\n\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});
\n

An easy way to send the SIGINT signal is with Control-C in most terminal\nprograms.\n\n

\n

Note:\n\n

\n\n

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

\n", "params": [] } ], "properties": [ { "textRaw": "process.stdout", "name": "stdout", "desc": "

A Writable Stream to stdout (on fd 1).\n\n

\n

For example, a console.log equivalent could look like this:\n\n

\n
console.log = function(msg) {\n  process.stdout.write(msg + '\\n');\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 are always blocking.\n\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

\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
\n

See the tty docs for more information.\n\n

\n" }, { "textRaw": "process.stderr", "name": "stderr", "desc": "

A writable stream to stderr (on fd 2).\n\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 are usually blocking.\n\n

\n\n" }, { "textRaw": "process.stdin", "name": "stdin", "desc": "

A Readable Stream for stdin (on fd 0).\n\n

\n

Example of opening standard input and listening for both events:\n\n

\n
process.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});
\n

As 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\nStream compatibility.\n\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

\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.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});
\n

This 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.execPath", "name": "execPath", "desc": "

This is the absolute pathname of the executable that started the process.\n\n

\n

Example:\n\n

\n
/usr/local/bin/node
\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

\n

Example:\n\n

\n
$ node --harmony script.js --version
\n

results in process.execArgv:\n\n

\n
['--harmony']
\n

and process.argv:\n\n

\n
['/usr/local/bin/node', 'script.js', '--version']
\n" }, { "textRaw": "process.env", "name": "env", "desc": "

An object containing the user environment. See environ(7).\n\n

\n

An 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' }
\n

You 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
\n

But this will:\n\n

\n
process.env.foo = 'bar';\nconsole.log(process.env.foo);
\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

\n

Specifying a code to process.exit(code) will override any previous\nsetting of process.exitCode.\n\n\n

\n" }, { "textRaw": "process.version", "name": "version", "desc": "

A compiled-in property that exposes NODE_VERSION.\n\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

\n
console.log(process.versions);
\n

Will 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" }, { "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

\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" }, { "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

\n

process.release contains the following properties:\n\n

\n\n

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' }
\n

In 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

\n" }, { "textRaw": "process.pid", "name": "pid", "desc": "

The PID of the process.\n\n

\n
console.log('This process is pid ' + process.pid);
\n" }, { "textRaw": "process.title", "name": "title", "desc": "

Getter/setter to set what is displayed in 'ps'.\n\n

\n

When used as a setter, the maximum length is platform-specific and probably\nshort.\n\n

\n

On 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

\n

v0.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

\n" }, { "textRaw": "process.arch", "name": "arch", "desc": "

What processor architecture you're running on: 'arm', 'ia32', or 'x64'.\n\n

\n
console.log('This processor architecture is ' + process.arch);
\n" }, { "textRaw": "process.platform", "name": "platform", "desc": "

What platform you're running on:\n'darwin', 'freebsd', 'linux', 'sunos' or 'win32'\n\n

\n
console.log('This platform is ' + process.platform);
\n" }, { "textRaw": "process.mainModule", "name": "mainModule", "desc": "

Alternate way to retrieve\nrequire.main.\nThe difference is that if the main module changes at runtime, require.main\nmight still refer to the original main module in modules that were required\nbefore the change occurred. Generally it's safe to assume that the two refer\nto the same module.\n\n

\n

As with require.main, it will be undefined if there was no entry script.\n\n

\n" } ], "methods": [ { "textRaw": "process.abort()", "type": "method", "name": "abort", "desc": "

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

\n
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", "signatures": [ { "params": [ { "name": "directory" } ] } ] }, { "textRaw": "process.cwd()", "type": "method", "name": "cwd", "desc": "

Returns the current working directory of the process.\n\n

\n
console.log('Current directory: ' + process.cwd());
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "process.exit([code])", "type": "method", "name": "exit", "desc": "

Ends the process with the specified code. If omitted, exit uses the\n'success' code 0.\n\n

\n

To exit with a 'failure' code:\n\n

\n
process.exit(1);
\n

The shell that executed Node.js should see the exit code as 1.\n\n\n

\n", "signatures": [ { "params": [ { "name": "code", "optional": true } ] } ] }, { "textRaw": "process.getgid()", "type": "method", "name": "getgid", "desc": "

Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n

\n

Gets the group identity of the process. (See getgid(2).)\nThis is the numerical group id, not the group name.\n\n

\n
if (process.getgid) {\n  console.log('Current gid: ' + process.getgid());\n}
\n", "signatures": [ { "params": [] } ] }, { "textRaw": "process.getegid()", "type": "method", "name": "getegid", "desc": "

Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n

\n

Gets the effective group identity of the process. (See getegid(2).)\nThis is the numerical group id, not the group name.\n\n

\n
if (process.getegid) {\n  console.log('Current gid: ' + process.getegid());\n}
\n", "signatures": [ { "params": [] } ] }, { "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

\n

Sets 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

\n
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", "signatures": [ { "params": [ { "name": "id" } ] } ] }, { "textRaw": "process.setegid(id)", "type": "method", "name": "setegid", "desc": "

Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n

\n

Sets 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

\n
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", "signatures": [ { "params": [ { "name": "id" } ] } ] }, { "textRaw": "process.getuid()", "type": "method", "name": "getuid", "desc": "

Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n

\n

Gets the user identity of the process. (See getuid(2).)\nThis is the numerical userid, not the username.\n\n

\n
if (process.getuid) {\n  console.log('Current uid: ' + process.getuid());\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

\n

Gets the effective user identity of the process. (See geteuid(2).)\nThis is the numerical userid, not the username.\n\n

\n
if (process.geteuid) {\n  console.log('Current uid: ' + process.geteuid());\n}
\n", "signatures": [ { "params": [] } ] }, { "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

\n

Sets 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

\n
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", "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

\n

Sets 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

\n
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", "signatures": [ { "params": [ { "name": "id" } ] } ] }, { "textRaw": "process.getgroups()", "type": "method", "name": "getgroups", "desc": "

Note: this function is only available on POSIX platforms (i.e. not Windows,\nAndroid)\n\n

\n

Returns 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

\n", "signatures": [ { "params": [] } ] }, { "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

\n

Sets the supplementary group IDs. This is a privileged operation, meaning you\nneed to be root or have the CAP_SETGID capability.\n\n

\n

The list can contain group IDs, group names or both.\n\n\n

\n", "signatures": [ { "params": [ { "name": "groups" } ] } ] }, { "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

\n

Reads /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

\n

user is a user name or user ID. extra_group is a group name or group ID.\n\n

\n

Some care needs to be taken when dropping privileges. Example:\n\n

\n
console.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

\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

\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

\n

Example of sending a signal to yourself:\n\n

\n
process.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');
\n

Note: When SIGUSR1 is received by Node.js it starts the debugger, see\nSignal 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

\n
var util = require('util');\n\nconsole.log(util.inspect(process.memoryUsage()));
\n

This will generate:\n\n

\n
{ rss: 4935680,\n  heapTotal: 1826816,\n  heapUsed: 650472 }
\n

heapTotal and heapUsed refer to V8's memory usage.\n\n\n

\n", "signatures": [ { "params": [] } ] }, { "textRaw": "process.nextTick(callback[, arg][, ...])", "type": "method", "name": "nextTick", "signatures": [ { "params": [ { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function" }, { "name": "arg", "optional": true }, { "name": "...", "optional": true } ] }, { "params": [ { "name": "callback" }, { "name": "arg", "optional": true }, { "name": "...", "optional": true } ] } ], "desc": "

Once the current event loop turn runs to completion, call the callback\nfunction.\n\n

\n

This 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

\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
\n

This 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

\n
function 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.
\n

It 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}
\n

This API is hazardous. If you do this:\n\n

\n
maybeSync(true, function() {\n  foo();\n});\nbar();
\n

then it's not clear whether foo() or bar() will be called first.\n\n

\n

This approach is much better:\n\n

\n
function definitelyAsync(arg, cb) {\n  if (arg) {\n    process.nextTick(cb);\n    return;\n  }\n\n  fs.stat('file', cb);\n}
\n

Note: 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

\n" }, { "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

\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

\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

\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

\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.send(message[, sendHandle][, callback])", "type": "method", "name": "send", "signatures": [ { "params": [ { "textRaw": "`message` {Object} ", "name": "message", "type": "Object" }, { "textRaw": "`sendHandle` {Handle object} ", "name": "sendHandle", "type": "Handle object", "optional": true }, { "name": "callback", "optional": true } ] }, { "params": [ { "name": "message" }, { "name": "sendHandle", "optional": true }, { "name": "callback", "optional": true } ] } ], "desc": "

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'\nevent on the parent's ChildProcess object.\n\n

\n

If Node.js was not spawned with an IPC channel, process.send() will be undefined.\n\n\n

\n" }, { "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

\n

Identical to the parent process's\nChildProcess.disconnect().\n\n

\n

If Node.js was not spawned with an IPC channel, process.disconnect() will be\nundefined.\n\n\n

\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\n

\n", "shortDesc": "Set to false after `process.disconnect()` is called" } ], "signatures": [ { "params": [] } ] } ] } ] }