df5d078a5d83e288781aa607aa317f8b8a0762ba
[platform/upstream/nodejs.git] / doc / api / process.markdown
1 # process
2
3 <!-- type=global -->
4
5 The `process` object is a global object and can be accessed from anywhere.
6 It is an instance of [`EventEmitter`][].
7
8 ## Event: 'beforeExit'
9
10 This event is emitted when Node.js empties its event loop and has nothing else to
11 schedule. Normally, Node.js exits when there is no work scheduled, but a listener
12 for `'beforeExit'` can make asynchronous calls, and cause Node.js to continue.
13
14 `'beforeExit'` is not emitted for conditions causing explicit termination, such as
15 [`process.exit()`][] or uncaught exceptions, and should not be used as an
16 alternative to the `'exit'` event unless the intention is to schedule more work.
17
18 ## Event: 'exit'
19
20 Emitted when the process is about to exit. There is no way to prevent the
21 exiting of the event loop at this point, and once all `'exit'` listeners have
22 finished running the process will exit. Therefore you **must** only perform
23 **synchronous** operations in this handler. This is a good hook to perform
24 checks on the module's state (like for unit tests). The callback takes one
25 argument, the code the process is exiting with.
26
27 This event is only emitted when Node.js exits explicitly by process.exit() or
28 implicitly by the event loop draining.
29
30 Example of listening for `'exit'`:
31
32     process.on('exit', (code) => {
33       // do *NOT* do this
34       setTimeout(() => {
35         console.log('This will not run');
36       }, 0);
37       console.log('About to exit with code:', code);
38     });
39
40 ## Event: 'message'
41
42 * `message` {Object} a parsed JSON object or primitive value
43 * `sendHandle` {Handle object} a [`net.Socket`][] or [`net.Server`][] object, or
44   undefined.
45
46 Messages sent by [`ChildProcess.send()`][] are obtained using the `'message'`
47 event on the child's process object.
48
49 ## Event: 'rejectionHandled'
50
51 Emitted whenever a Promise was rejected and an error handler was attached to it
52 (for example with `.catch()`) later than after an event loop turn. This event
53 is emitted with the following arguments:
54
55  - `p` the promise that was previously emitted in an `'unhandledRejection'`
56  event, but which has now gained a rejection handler.
57
58 There is no notion of a top level for a promise chain at which rejections can
59 always be handled. Being inherently asynchronous in nature, a promise rejection
60 can be handled at a future point in time — possibly much later than the
61 event loop turn it takes for the `'unhandledRejection'` event to be emitted.
62
63 Another way of stating this is that, unlike in synchronous code where there is
64 an ever-growing list of unhandled exceptions, with promises there is a
65 growing-and-shrinking list of unhandled rejections. In synchronous code, the
66 `'uncaughtException'` event tells you when the list of unhandled exceptions
67 grows. And in asynchronous code, the `'unhandledRejection'` event tells you
68 when the list of unhandled rejections grows, while the `'rejectionHandled'`
69 event tells you when the list of unhandled rejections shrinks.
70
71 For example using the rejection detection hooks in order to keep a map of all
72 the rejected promise reasons at a given time:
73
74     const unhandledRejections = new Map();
75     process.on('unhandledRejection', (reason, p) => {
76       unhandledRejections.set(p, reason);
77     });
78     process.on('rejectionHandled', (p) => {
79       unhandledRejections.delete(p);
80     });
81
82 This map will grow and shrink over time, reflecting rejections that start
83 unhandled and then become handled. You could record the errors in some error
84 log, either periodically (probably best for long-running programs, allowing
85 you to clear the map, which in the case of a very buggy program could grow
86 indefinitely) or upon process exit (more convenient for scripts).
87
88 ## Event: 'uncaughtException'
89
90 Emitted when an exception bubbles all the way back to the event loop. If a
91 listener is added for this exception, the default action (which is to print
92 a stack trace and exit) will not occur.
93
94 Example of listening for `'uncaughtException'`:
95
96     process.on('uncaughtException', (err) => {
97       console.log(`Caught exception: ${err}`);
98     });
99
100     setTimeout(() => {
101       console.log('This will still run.');
102     }, 500);
103
104     // Intentionally cause an exception, but don't catch it.
105     nonexistentFunc();
106     console.log('This will not run.');
107
108 Note that `'uncaughtException'` is a very crude mechanism for exception
109 handling.
110
111 Do *not* use it as the Node.js equivalent of `On Error Resume Next`. An
112 unhandled exception means your application - and by extension Node.js itself -
113 is in an undefined state. Blindly resuming means *anything* could happen.
114
115 Exceptions thrown from within the event handler will not be caught. Instead the
116 process will exit with a non zero exit code and the stack trace will be printed.
117 This is to avoid infinite recursion.
118
119 Think of resuming as pulling the power cord when you are upgrading your system.
120 Nine out of ten times nothing happens - but the 10th time, your system is bust.
121
122 `'uncaughtException'` should be used to perform synchronous cleanup before
123 shutting down the process. It is not safe to resume normal operation after
124 `'uncaughtException'`. If you do use it, restart your application after every
125 unhandled exception!
126
127 You have been warned.
128
129 ## Event: 'unhandledRejection'
130
131 Emitted whenever a `Promise` is rejected and no error handler is attached to
132 the promise within a turn of the event loop. When programming with promises
133 exceptions are encapsulated as rejected promises. Such promises can be caught
134 and handled using [`promise.catch(...)`][] and rejections are propagated through
135 a promise chain. This event is useful for detecting and keeping track of
136 promises that were rejected whose rejections were not handled yet. This event
137 is emitted with the following arguments:
138
139  - `reason` the object with which the promise was rejected (usually an [`Error`][]
140 instance).
141  - `p` the promise that was rejected.
142
143 Here is an example that logs every unhandled rejection to the console
144
145     process.on('unhandledRejection', (reason, p) => {
146         console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);
147         // application specific logging, throwing an error, or other logic here
148     });
149
150 For example, here is a rejection that will trigger the `'unhandledRejection'`
151 event:
152
153     somePromise.then((res) => {
154       return reportToUser(JSON.parse(res)); // note the typo
155     }); // no `.catch` or `.then`
156
157 Here is an example of a coding pattern that will also trigger
158 `'unhandledRejection'`:
159
160     function SomeResource() {
161       // Initially set the loaded status to a rejected promise
162       this.loaded = Promise.reject(new Error('Resource not yet loaded!'));
163     }
164
165     var resource = new SomeResource();
166     // no .catch or .then on resource.loaded for at least a turn
167
168 In cases like this, you may not want to track the rejection as a developer
169 error like you would for other `'unhandledRejection'` events. To address
170 this, you can either attach a dummy `.catch(function() { })` handler to
171 `resource.loaded`, preventing the `'unhandledRejection'` event from being
172 emitted, or you can use the `'rejectionHandled'` event. Below is an
173 explanation of how to do that.
174
175 ## Exit Codes
176
177 Node.js will normally exit with a `0` status code when no more async
178 operations are pending.  The following status codes are used in other
179 cases:
180
181 * `1` **Uncaught Fatal Exception** - There was an uncaught exception,
182   and it was not handled by a domain or an `'uncaughtException'` event
183   handler.
184 * `2` - Unused (reserved by Bash for builtin misuse)
185 * `3` **Internal JavaScript Parse Error** - The JavaScript source code
186   internal in Node.js's bootstrapping process caused a parse error.  This
187   is extremely rare, and generally can only happen during development
188   of Node.js itself.
189 * `4` **Internal JavaScript Evaluation Failure** - The JavaScript
190   source code internal in Node.js's bootstrapping process failed to
191   return a function value when evaluated.  This is extremely rare, and
192   generally can only happen during development of Node.js itself.
193 * `5` **Fatal Error** - There was a fatal unrecoverable error in V8.
194   Typically a message will be printed to stderr with the prefix `FATAL
195   ERROR`.
196 * `6` **Non-function Internal Exception Handler** - There was an
197   uncaught exception, but the internal fatal exception handler
198   function was somehow set to a non-function, and could not be called.
199 * `7` **Internal Exception Handler Run-Time Failure** - There was an
200   uncaught exception, and the internal fatal exception handler
201   function itself threw an error while attempting to handle it.  This
202   can happen, for example, if a `process.on('uncaughtException')` or
203   `domain.on('error')` handler throws an error.
204 * `8` - Unused.  In previous versions of Node.js, exit code 8 sometimes
205   indicated an uncaught exception.
206 * `9` - **Invalid Argument** - Either an unknown option was specified,
207   or an option requiring a value was provided without a value.
208 * `10` **Internal JavaScript Run-Time Failure** - The JavaScript
209   source code internal in Node.js's bootstrapping process threw an error
210   when the bootstrapping function was called.  This is extremely rare,
211   and generally can only happen during development of Node.js itself.
212 * `12` **Invalid Debug Argument** - The `--debug` and/or `--debug-brk`
213   options were set, but an invalid port number was chosen.
214 * `>128` **Signal Exits** - If Node.js receives a fatal signal such as
215   `SIGKILL` or `SIGHUP`, then its exit code will be `128` plus the
216   value of the signal code.  This is a standard Unix practice, since
217   exit codes are defined to be 7-bit integers, and signal exits set
218   the high-order bit, and then contain the value of the signal code.
219
220 ## Signal Events
221
222 <!--type=event-->
223 <!--name=SIGINT, SIGHUP, etc.-->
224
225 Emitted when the processes receives a signal. See sigaction(2) for a list of
226 standard POSIX signal names such as `SIGINT`, `SIGHUP`, etc.
227
228 Example of listening for `SIGINT`:
229
230     // Start reading from stdin so we don't exit.
231     process.stdin.resume();
232
233     process.on('SIGINT', () => {
234       console.log('Got SIGINT.  Press Control-D to exit.');
235     });
236
237 An easy way to send the `SIGINT` signal is with `Control-C` in most terminal
238 programs.
239
240 Note:
241
242 - `SIGUSR1` is reserved by Node.js to start the debugger.  It's possible to
243   install a listener but that won't stop the debugger from starting.
244 - `SIGTERM` and `SIGINT` have default handlers on non-Windows platforms that resets
245   the terminal mode before exiting with code `128 + signal number`. If one of
246   these signals has a listener installed, its default behavior will be removed
247   (Node.js will no longer exit).
248 - `SIGPIPE` is ignored by default. It can have a listener installed.
249 - `SIGHUP` is generated on Windows when the console window is closed, and on other
250   platforms under various similar conditions, see signal(7). It can have a
251   listener installed, however Node.js will be unconditionally terminated by
252   Windows about 10 seconds later. On non-Windows platforms, the default
253   behavior of `SIGHUP` is to terminate Node.js, but once a listener has been
254   installed its default behavior will be removed.
255 - `SIGTERM` is not supported on Windows, it can be listened on.
256 - `SIGINT` from the terminal is supported on all platforms, and can usually be
257   generated with `CTRL+C` (though this may be configurable). It is not generated
258   when terminal raw mode is enabled.
259 - `SIGBREAK` is delivered on Windows when `CTRL+BREAK` is pressed, on non-Windows
260   platforms it can be listened on, but there is no way to send or generate it.
261 - `SIGWINCH` is delivered when the console has been resized. On Windows, this will
262   only happen on write to the console when the cursor is being moved, or when a
263   readable tty is used in raw mode.
264 - `SIGKILL` cannot have a listener installed, it will unconditionally terminate
265   Node.js on all platforms.
266 - `SIGSTOP` cannot have a listener installed.
267
268 Note that Windows does not support sending Signals, but Node.js offers some
269 emulation with `process.kill()`, and `child_process.kill()`. Sending signal `0`
270 can be used to test for the existence of a process. Sending `SIGINT`,
271 `SIGTERM`, and `SIGKILL` cause the unconditional termination of the target
272 process.
273
274 ## process.abort()
275
276 This causes Node.js to emit an abort. This will cause Node.js to exit and
277 generate a core file.
278
279 ## process.arch
280
281 What processor architecture you're running on: `'arm'`, `'ia32'`, or `'x64'`.
282
283     console.log('This processor architecture is ' + process.arch);
284
285 ## process.argv
286
287 An array containing the command line arguments.  The first element will be
288 'node', the second element will be the name of the JavaScript file.  The
289 next elements will be any additional command line arguments.
290
291     // print process.argv
292     process.argv.forEach((val, index, array) => {
293       console.log(`${index}: ${val}`);
294     });
295
296 This will generate:
297
298     $ node process-2.js one two=three four
299     0: node
300     1: /Users/mjr/work/node/process-2.js
301     2: one
302     3: two=three
303     4: four
304
305 ## process.chdir(directory)
306
307 Changes the current working directory of the process or throws an exception if that fails.
308
309     console.log(`Starting directory: ${process.cwd()}`);
310     try {
311       process.chdir('/tmp');
312       console.log(`New directory: ${process.cwd()}`);
313     }
314     catch (err) {
315       console.log(`chdir: ${err}`);
316     }
317
318 ## process.config
319
320 An Object containing the JavaScript representation of the configure options
321 that were used to compile the current Node.js executable. This is the same as
322 the `config.gypi` file that was produced when running the `./configure` script.
323
324 An example of the possible output looks like:
325
326     { target_defaults:
327        { cflags: [],
328          default_configuration: 'Release',
329          defines: [],
330          include_dirs: [],
331          libraries: [] },
332       variables:
333        { host_arch: 'x64',
334          node_install_npm: 'true',
335          node_prefix: '',
336          node_shared_cares: 'false',
337          node_shared_http_parser: 'false',
338          node_shared_libuv: 'false',
339          node_shared_zlib: 'false',
340          node_use_dtrace: 'false',
341          node_use_openssl: 'true',
342          node_shared_openssl: 'false',
343          strict_aliasing: 'true',
344          target_arch: 'x64',
345          v8_use_snapshot: 'true' } }
346
347 ## process.connected
348
349 * {Boolean} Set to false after `process.disconnect()` is called
350
351 If `process.connected` is false, it is no longer possible to send messages.
352
353 ## process.cwd()
354
355 Returns the current working directory of the process.
356
357     console.log(`Current directory: ${process.cwd()}`);
358
359 ## process.disconnect()
360
361 Close the IPC channel to the parent process, allowing this child to exit
362 gracefully once there are no other connections keeping it alive.
363
364 Identical to the parent process's [`ChildProcess.disconnect()`][].
365
366 If Node.js was not spawned with an IPC channel, `process.disconnect()` will be
367 undefined.
368
369 ## process.env
370
371 An object containing the user environment. See environ(7).
372
373 An example of this object looks like:
374
375     { TERM: 'xterm-256color',
376       SHELL: '/usr/local/bin/bash',
377       USER: 'maciej',
378       PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
379       PWD: '/Users/maciej',
380       EDITOR: 'vim',
381       SHLVL: '1',
382       HOME: '/Users/maciej',
383       LOGNAME: 'maciej',
384       _: '/usr/local/bin/node' }
385
386 You can write to this object, but changes won't be reflected outside of your
387 process. That means that the following won't work:
388
389     $ node -e 'process.env.foo = "bar"' && echo $foo
390
391 But this will:
392
393     process.env.foo = 'bar';
394     console.log(process.env.foo);
395
396 Assigning a property on `process.env` will implicitly convert the value
397 to a string.
398
399 Example:
400
401 ```js
402 process.env.test = null;
403 console.log(process.env.test);
404 // => 'null'
405 process.env.test = undefined;
406 console.log(process.env.test);
407 // => 'undefined'
408 ```
409
410 Use `delete` to delete a property from `process.env`.
411
412 Example:
413
414 ```js
415 process.env.TEST = 1;
416 delete process.env.TEST;
417 console.log(process.env.TEST);
418 // => undefined
419 ```
420
421 ## process.execArgv
422
423 This is the set of Node.js-specific command line options from the
424 executable that started the process.  These options do not show up in
425 `process.argv`, and do not include the Node.js executable, the name of
426 the script, or any options following the script name. These options
427 are useful in order to spawn child processes with the same execution
428 environment as the parent.
429
430 Example:
431
432     $ node --harmony script.js --version
433
434 results in process.execArgv:
435
436     ['--harmony']
437
438 and process.argv:
439
440     ['/usr/local/bin/node', 'script.js', '--version']
441
442 ## process.execPath
443
444 This is the absolute pathname of the executable that started the process.
445
446 Example:
447
448     /usr/local/bin/node
449
450
451 ## process.exit([code])
452
453 Ends the process with the specified `code`.  If omitted, exit uses the
454 'success' code `0`.
455
456 To exit with a 'failure' code:
457
458     process.exit(1);
459
460 The shell that executed Node.js should see the exit code as 1.
461
462
463 ## process.exitCode
464
465 A number which will be the process exit code, when the process either
466 exits gracefully, or is exited via [`process.exit()`][] without specifying
467 a code.
468
469 Specifying a code to `process.exit(code)` will override any previous
470 setting of `process.exitCode`.
471
472
473 ## process.getegid()
474
475 Note: this function is only available on POSIX platforms (i.e. not Windows,
476 Android)
477
478 Gets the effective group identity of the process. (See getegid(2).)
479 This is the numerical group id, not the group name.
480
481     if (process.getegid) {
482       console.log(`Current gid: ${process.getegid()}`);
483     }
484
485
486 ## process.geteuid()
487
488 Note: this function is only available on POSIX platforms (i.e. not Windows,
489 Android)
490
491 Gets the effective user identity of the process. (See geteuid(2).)
492 This is the numerical userid, not the username.
493
494     if (process.geteuid) {
495       console.log(`Current uid: ${process.geteuid()}`);
496     }
497
498 ## process.getgid()
499
500 Note: this function is only available on POSIX platforms (i.e. not Windows,
501 Android)
502
503 Gets the group identity of the process. (See getgid(2).)
504 This is the numerical group id, not the group name.
505
506     if (process.getgid) {
507       console.log(`Current gid: ${process.getgid()}`);
508     }
509
510 ## process.getgroups()
511
512 Note: this function is only available on POSIX platforms (i.e. not Windows,
513 Android)
514
515 Returns an array with the supplementary group IDs. POSIX leaves it unspecified
516 if the effective group ID is included but Node.js ensures it always is.
517
518 ## process.getuid()
519
520 Note: this function is only available on POSIX platforms (i.e. not Windows,
521 Android)
522
523 Gets the user identity of the process. (See getuid(2).)
524 This is the numerical userid, not the username.
525
526     if (process.getuid) {
527       console.log(`Current uid: ${process.getuid()}`);
528     }
529
530 ## process.hrtime()
531
532 Returns the current high-resolution real time in a `[seconds, nanoseconds]`
533 tuple Array. It is relative to an arbitrary time in the past. It is not
534 related to the time of day and therefore not subject to clock drift. The
535 primary use is for measuring performance between intervals.
536
537 You may pass in the result of a previous call to `process.hrtime()` to get
538 a diff reading, useful for benchmarks and measuring intervals:
539
540     var time = process.hrtime();
541     // [ 1800216, 25 ]
542
543     setTimeout(() => {
544       var diff = process.hrtime(time);
545       // [ 1, 552 ]
546
547       console.log('benchmark took %d nanoseconds', diff[0] * 1e9 + diff[1]);
548       // benchmark took 1000000527 nanoseconds
549     }, 1000);
550
551
552 ## process.initgroups(user, extra_group)
553
554 Note: this function is only available on POSIX platforms (i.e. not Windows,
555 Android)
556
557 Reads /etc/group and initializes the group access list, using all groups of
558 which the user is a member. This is a privileged operation, meaning you need
559 to be root or have the `CAP_SETGID` capability.
560
561 `user` is a user name or user ID. `extra_group` is a group name or group ID.
562
563 Some care needs to be taken when dropping privileges. Example:
564
565     console.log(process.getgroups());         // [ 0 ]
566     process.initgroups('bnoordhuis', 1000);   // switch user
567     console.log(process.getgroups());         // [ 27, 30, 46, 1000, 0 ]
568     process.setgid(1000);                     // drop root gid
569     console.log(process.getgroups());         // [ 27, 30, 46, 1000 ]
570
571 ## process.kill(pid[, signal])
572
573 Send a signal to a process. `pid` is the process id and `signal` is the
574 string describing the signal to send.  Signal names are strings like
575 `SIGINT` or `SIGHUP`.  If omitted, the signal will be `SIGTERM`.
576 See [Signal Events][] and kill(2) for more information.
577
578 Will throw an error if target does not exist, and as a special case, a signal
579 of `0` can be used to test for the existence of a process. Windows platforms
580 will throw an error if the `pid` is used to kill a process group.
581
582 Note that even though the name of this function is `process.kill`, it is really
583 just a signal sender, like the `kill` system call.  The signal sent may do
584 something other than kill the target process.
585
586 Example of sending a signal to yourself:
587
588     process.on('SIGHUP', () => {
589       console.log('Got SIGHUP signal.');
590     });
591
592     setTimeout(() => {
593       console.log('Exiting.');
594       process.exit(0);
595     }, 100);
596
597     process.kill(process.pid, 'SIGHUP');
598
599 Note: When SIGUSR1 is received by Node.js it starts the debugger, see
600 [Signal Events][].
601
602 ## process.mainModule
603
604 Alternate way to retrieve [`require.main`][]. The difference is that if the main
605 module changes at runtime, `require.main` might still refer to the original main
606 module in modules that were required before the change occurred. Generally it's
607 safe to assume that the two refer to the same module.
608
609 As with `require.main`, it will be `undefined` if there was no entry script.
610
611 ## process.memoryUsage()
612
613 Returns an object describing the memory usage of the Node.js process
614 measured in bytes.
615
616     const util = require('util');
617
618     console.log(util.inspect(process.memoryUsage()));
619
620 This will generate:
621
622     { rss: 4935680,
623       heapTotal: 1826816,
624       heapUsed: 650472 }
625
626 `heapTotal` and `heapUsed` refer to V8's memory usage.
627
628
629 ## process.nextTick(callback[, arg][, ...])
630
631 * `callback` {Function}
632
633 Once the current event loop turn runs to completion, call the callback
634 function.
635
636 This is *not* a simple alias to [`setTimeout(fn, 0)`][], it's much more
637 efficient.  It runs before any additional I/O events (including
638 timers) fire in subsequent ticks of the event loop.
639
640     console.log('start');
641     process.nextTick(() => {
642       console.log('nextTick callback');
643     });
644     console.log('scheduled');
645     // Output:
646     // start
647     // scheduled
648     // nextTick callback
649
650 This is important in developing APIs where you want to give the user the
651 chance to assign event handlers after an object has been constructed,
652 but before any I/O has occurred.
653
654     function MyThing(options) {
655       this.setupOptions(options);
656
657       process.nextTick(() => {
658         this.startDoingStuff();
659       });
660     }
661
662     var thing = new MyThing();
663     thing.getReadyForStuff();
664
665     // thing.startDoingStuff() gets called now, not before.
666
667 It is very important for APIs to be either 100% synchronous or 100%
668 asynchronous.  Consider this example:
669
670     // WARNING!  DO NOT USE!  BAD UNSAFE HAZARD!
671     function maybeSync(arg, cb) {
672       if (arg) {
673         cb();
674         return;
675       }
676
677       fs.stat('file', cb);
678     }
679
680 This API is hazardous.  If you do this:
681
682     maybeSync(true, function() {
683       foo();
684     });
685     bar();
686
687 then it's not clear whether `foo()` or `bar()` will be called first.
688
689 This approach is much better:
690
691     function definitelyAsync(arg, cb) {
692       if (arg) {
693         process.nextTick(cb);
694         return;
695       }
696
697       fs.stat('file', cb);
698     }
699
700 Note: the nextTick queue is completely drained on each pass of the
701 event loop **before** additional I/O is processed.  As a result,
702 recursively setting nextTick callbacks will block any I/O from
703 happening, just like a `while(true);` loop.
704
705 ## process.pid
706
707 The PID of the process.
708
709     console.log(`This process is pid ${process.pid}`);
710
711 ## process.platform
712
713 What platform you're running on:
714 `'darwin'`, `'freebsd'`, `'linux'`, `'sunos'` or `'win32'`
715
716     console.log(`This platform is ${process.platform}`);
717
718 ## process.release
719
720 An Object containing metadata related to the current release, including URLs
721 for the source tarball and headers-only tarball.
722
723 `process.release` contains the following properties:
724
725 * `name`: a string with a value that will always be `'node'` for Node.js. For
726   legacy io.js releases, this will be `'io.js'`.
727 * `sourceUrl`: a complete URL pointing to a _.tar.gz_ file containing the
728   source of the current release.
729 * `headersUrl`: a complete URL pointing to a _.tar.gz_ file containing only
730   the header files for the current release. This file is significantly smaller
731   than the full source file and can be used for compiling add-ons against
732   Node.js.
733 * `libUrl`: a complete URL pointing to an _node.lib_ file matching the
734   architecture and version of the current release. This file is used for
735   compiling add-ons against Node.js. _This property is only present on Windows
736   builds of Node.js and will be missing on all other platforms._
737
738 e.g.
739
740     { name: 'node',
741       sourceUrl: 'https://nodejs.org/download/release/v4.0.0/node-v4.0.0.tar.gz',
742       headersUrl: 'https://nodejs.org/download/release/v4.0.0/node-v4.0.0-headers.tar.gz',
743       libUrl: 'https://nodejs.org/download/release/v4.0.0/win-x64/node.lib' }
744
745 In custom builds from non-release versions of the source tree, only the
746 `name` property may be present. The additional properties should not be
747 relied upon to exist.
748
749 ## process.send(message[, sendHandle][, callback])
750
751 * `message` {Object}
752 * `sendHandle` {Handle object}
753 * `callback` {Function}
754 * Return: {Boolean}
755
756 When Node.js is spawned with an IPC channel attached, it can send messages to its
757 parent process using `process.send()`. Each will be received as a
758 [`'message'`][] event on the parent's `ChildProcess` object.
759
760 If Node.js was not spawned with an IPC channel, `process.send()` will be undefined.
761
762 ## process.setegid(id)
763
764 Note: this function is only available on POSIX platforms (i.e. not Windows,
765 Android)
766
767 Sets the effective group identity of the process. (See setegid(2).)
768 This accepts either a numerical ID or a groupname string. If a groupname
769 is specified, this method blocks while resolving it to a numerical ID.
770
771     if (process.getegid && process.setegid) {
772       console.log(`Current gid: ${process.getegid()}`);
773       try {
774         process.setegid(501);
775         console.log(`New gid: ${process.getegid()}`);
776       }
777       catch (err) {
778         console.log(`Failed to set gid: ${err}`);
779       }
780     }
781
782 ## process.seteuid(id)
783
784 Note: this function is only available on POSIX platforms (i.e. not Windows,
785 Android)
786
787 Sets the effective user identity of the process. (See seteuid(2).)
788 This accepts either a numerical ID or a username string.  If a username
789 is specified, this method blocks while resolving it to a numerical ID.
790
791     if (process.geteuid && process.seteuid) {
792       console.log(`Current uid: ${process.geteuid()}`);
793       try {
794         process.seteuid(501);
795         console.log(`New uid: ${process.geteuid()}`);
796       }
797       catch (err) {
798         console.log(`Failed to set uid: ${err}`);
799       }
800     }
801
802 ## process.setgid(id)
803
804 Note: this function is only available on POSIX platforms (i.e. not Windows,
805 Android)
806
807 Sets the group identity of the process. (See setgid(2).)  This accepts either
808 a numerical ID or a groupname string. If a groupname is specified, this method
809 blocks while resolving it to a numerical ID.
810
811     if (process.getgid && process.setgid) {
812       console.log(`Current gid: ${process.getgid()}`);
813       try {
814         process.setgid(501);
815         console.log(`New gid: ${process.getgid()}`);
816       }
817       catch (err) {
818         console.log(`Failed to set gid: ${err}`);
819       }
820     }
821
822 ## process.setgroups(groups)
823
824 Note: this function is only available on POSIX platforms (i.e. not Windows,
825 Android)
826
827 Sets the supplementary group IDs. This is a privileged operation, meaning you
828 need to be root or have the `CAP_SETGID` capability.
829
830 The list can contain group IDs, group names or both.
831
832 ## process.setuid(id)
833
834 Note: this function is only available on POSIX platforms (i.e. not Windows,
835 Android)
836
837 Sets the user identity of the process. (See setuid(2).)  This accepts either
838 a numerical ID or a username string.  If a username is specified, this method
839 blocks while resolving it to a numerical ID.
840
841     if (process.getuid && process.setuid) {
842       console.log(`Current uid: ${process.getuid()}`);
843       try {
844         process.setuid(501);
845         console.log(`New uid: ${process.getuid()}`);
846       }
847       catch (err) {
848         console.log(`Failed to set uid: ${err}`);
849       }
850     }
851
852 ## process.stderr
853
854 A writable stream to stderr (on fd `2`).
855
856 `process.stderr` and `process.stdout` are unlike other streams in Node.js in
857 that they cannot be closed (`end()` will throw), they never emit the `finish`
858 event and that writes can block when output is redirected to a file (although
859 disks are fast and operating systems normally employ write-back caching so it
860 should be a very rare occurrence indeed.)
861
862 ## process.stdin
863
864 A `Readable Stream` for stdin (on fd `0`).
865
866 Example of opening standard input and listening for both events:
867
868     process.stdin.setEncoding('utf8');
869
870     process.stdin.on('readable', () => {
871       var chunk = process.stdin.read();
872       if (chunk !== null) {
873         process.stdout.write(`data: ${chunk}`);
874       }
875     });
876
877     process.stdin.on('end', () => {
878       process.stdout.write('end');
879     });
880
881 As a Stream, `process.stdin` can also be used in "old" mode that is compatible
882 with scripts written for node.js prior to v0.10.
883 For more information see [Stream compatibility][].
884
885 In "old" Streams mode the stdin stream is paused by default, so one
886 must call `process.stdin.resume()` to read from it. Note also that calling
887 `process.stdin.resume()` itself would switch stream to "old" mode.
888
889 If you are starting a new project you should prefer a more recent "new" Streams
890 mode over "old" one.
891
892 ## process.stdout
893
894 A `Writable Stream` to `stdout` (on fd `1`).
895
896 For example, a `console.log` equivalent could look like this:
897
898     console.log = function(msg) {
899       process.stdout.write(`${msg}\n`);
900     };
901
902 `process.stderr` and `process.stdout` are unlike other streams in Node.js in
903 that they cannot be closed (`end()` will throw), they never emit the `'finish'`
904 event and that writes can block when output is redirected to a file (although
905 disks are fast and operating systems normally employ write-back caching so it
906 should be a very rare occurrence indeed.)
907
908 To check if Node.js is being run in a TTY context, read the `isTTY` property
909 on `process.stderr`, `process.stdout`, or `process.stdin`:
910
911     $ node -p "Boolean(process.stdin.isTTY)"
912     true
913     $ echo "foo" | node -p "Boolean(process.stdin.isTTY)"
914     false
915
916     $ node -p "Boolean(process.stdout.isTTY)"
917     true
918     $ node -p "Boolean(process.stdout.isTTY)" | cat
919     false
920
921 See [the tty docs][] for more information.
922
923 ## process.title
924
925 Getter/setter to set what is displayed in `ps`.
926
927 When used as a setter, the maximum length is platform-specific and probably
928 short.
929
930 On Linux and OS X, it's limited to the size of the binary name plus the
931 length of the command line arguments because it overwrites the argv memory.
932
933 v0.8 allowed for longer process title strings by also overwriting the environ
934 memory but that was potentially insecure/confusing in some (rather obscure)
935 cases.
936
937 ## process.umask([mask])
938
939 Sets or reads the process's file mode creation mask. Child processes inherit
940 the mask from the parent process. Returns the old mask if `mask` argument is
941 given, otherwise returns the current mask.
942
943     const newmask = 0o022;
944     const oldmask = process.umask(newmask);
945     console.log(
946       `Changed umask from ${oldmask.toString(8)} to ${newmask.toString(8)}`
947     );
948
949
950 ## process.uptime()
951
952 Number of seconds Node.js has been running.
953
954 ## process.version
955
956 A compiled-in property that exposes `NODE_VERSION`.
957
958     console.log(`Version: ${process.version}`);
959
960 ## process.versions
961
962 A property exposing version strings of Node.js and its dependencies.
963
964     console.log(process.versions);
965
966 Will print something like:
967
968     { http_parser: '2.3.0',
969       node: '1.1.1',
970       v8: '4.1.0.14',
971       uv: '1.3.0',
972       zlib: '1.2.8',
973       ares: '1.10.0-DEV',
974       modules: '43',
975       icu: '55.1',
976       openssl: '1.0.1k' }
977
978 [`'message'`]: child_process.html#child_process_event_message
979 [`ChildProcess.disconnect()`]: child_process.html#child_process_child_disconnect
980 [`ChildProcess.send()`]: child_process.html#child_process_child_send_message_sendhandle_callback
981 [`Error`]: errors.html#errors_class_error
982 [`EventEmitter`]: events.html#events_class_events_eventemitter
983 [`net.Server`]: net.html#net_class_net_server
984 [`net.Socket`]: net.html#net_class_net_socket
985 [`process.exit()`]: #process_process_exit_code
986 [`promise.catch(...)`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
987 [`require.main`]: modules.html#modules_accessing_the_main_module
988 [`setTimeout(fn, 0)`]: timers.html#timers_settimeout_callback_delay_arg
989 [Signal Events]: #process_signal_events
990 [Stream compatibility]: stream.html#stream_compatibility_with_older_node_js_versions
991 [the tty docs]: tty.html#tty_tty