|
|
@ -7,7 +7,7 @@ It is an instance of [EventEmitter][]. |
|
|
|
|
|
|
|
## Exit Codes |
|
|
|
|
|
|
|
Node will normally exit with a `0` status code when no more async |
|
|
|
io.js will normally exit with a `0` status code when no more async |
|
|
|
operations are pending. The following status codes are used in other |
|
|
|
cases: |
|
|
|
|
|
|
@ -16,13 +16,13 @@ cases: |
|
|
|
handler. |
|
|
|
* `2` - Unused (reserved by Bash for builtin misuse) |
|
|
|
* `3` **Internal JavaScript Parse Error** - The JavaScript source code |
|
|
|
internal in Node's bootstrapping process caused a parse error. This |
|
|
|
internal in io.js's bootstrapping process caused a parse error. This |
|
|
|
is extremely rare, and generally can only happen during development |
|
|
|
of Node itself. |
|
|
|
of io.js itself. |
|
|
|
* `4` **Internal JavaScript Evaluation Failure** - The JavaScript |
|
|
|
source code internal in Node's bootstrapping process failed to |
|
|
|
source code internal in io.js's bootstrapping process failed to |
|
|
|
return a function value when evaluated. This is extremely rare, and |
|
|
|
generally can only happen during development of Node itself. |
|
|
|
generally can only happen during development of io.js itself. |
|
|
|
* `5` **Fatal Error** - There was a fatal unrecoverable error in V8. |
|
|
|
Typically a message will be printed to stderr with the prefix `FATAL |
|
|
|
ERROR`. |
|
|
@ -34,17 +34,17 @@ cases: |
|
|
|
function itself threw an error while attempting to handle it. This |
|
|
|
can happen, for example, if a `process.on('uncaughtException')` or |
|
|
|
`domain.on('error')` handler throws an error. |
|
|
|
* `8` - Unused. In previous versions of Node, exit code 8 sometimes |
|
|
|
* `8` - Unused. In previous versions of io.js, exit code 8 sometimes |
|
|
|
indicated an uncaught exception. |
|
|
|
* `9` - **Invalid Argument** - Either an unknown option was specified, |
|
|
|
or an option requiring a value was provided without a value. |
|
|
|
* `10` **Internal JavaScript Run-Time Failure** - The JavaScript |
|
|
|
source code internal in Node's bootstrapping process threw an error |
|
|
|
source code internal in io.js's bootstrapping process threw an error |
|
|
|
when the bootstrapping function was called. This is extremely rare, |
|
|
|
and generally can only happen during development of Node itself. |
|
|
|
and generally can only happen during development of io.js itself. |
|
|
|
* `12` **Invalid Debug Argument** - The `--debug` and/or `--debug-brk` |
|
|
|
options were set, but an invalid port number was chosen. |
|
|
|
* `>128` **Signal Exits** - If Node receives a fatal signal such as |
|
|
|
* `>128` **Signal Exits** - If io.js receives a fatal signal such as |
|
|
|
`SIGKILL` or `SIGHUP`, then its exit code will be `128` plus the |
|
|
|
value of the signal code. This is a standard Unix practice, since |
|
|
|
exit codes are defined to be 7-bit integers, and signal exits set |
|
|
@ -72,9 +72,9 @@ Example of listening for `exit`: |
|
|
|
|
|
|
|
## Event: 'beforeExit' |
|
|
|
|
|
|
|
This event is emitted when node empties it's event loop and has nothing else to |
|
|
|
schedule. Normally, node exits when there is no work scheduled, but a listener |
|
|
|
for 'beforeExit' can make asynchronous calls, and cause node to continue. |
|
|
|
This event is emitted when io.js empties it's event loop and has nothing else to |
|
|
|
schedule. Normally, io.js exits when there is no work scheduled, but a listener |
|
|
|
for 'beforeExit' can make asynchronous calls, and cause io.js to continue. |
|
|
|
|
|
|
|
'beforeExit' is not emitted for conditions causing explicit termination, such as |
|
|
|
`process.exit()` or uncaught exceptions, and should not be used as an |
|
|
@ -107,8 +107,8 @@ handling. |
|
|
|
Don't use it, use [domains](domain.html) instead. If you do use it, restart |
|
|
|
your application after every unhandled exception! |
|
|
|
|
|
|
|
Do *not* use it as the node.js equivalent of `On Error Resume Next`. An |
|
|
|
unhandled exception means your application - and by extension node.js itself - |
|
|
|
Do *not* use it as the io.js equivalent of `On Error Resume Next`. An |
|
|
|
unhandled exception means your application - and by extension io.js itself - |
|
|
|
is in an undefined state. Blindly resuming means *anything* could happen. |
|
|
|
|
|
|
|
Think of resuming as pulling the power cord when you are upgrading your system. |
|
|
@ -138,19 +138,19 @@ programs. |
|
|
|
|
|
|
|
Note: |
|
|
|
|
|
|
|
- `SIGUSR1` is reserved by node.js to start the debugger. It's possible to |
|
|
|
- `SIGUSR1` is reserved by io.js to start the debugger. It's possible to |
|
|
|
install a listener but that won't stop the debugger from starting. |
|
|
|
- `SIGTERM` and `SIGINT` have default handlers on non-Windows platforms that resets |
|
|
|
the terminal mode before exiting with code `128 + signal number`. If one of |
|
|
|
these signals has a listener installed, its default behaviour will be removed |
|
|
|
(node will no longer exit). |
|
|
|
(io.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 |
|
|
|
platforms under various similar conditions, see signal(7). It can have a |
|
|
|
listener installed, however node will be unconditionally terminated by Windows |
|
|
|
about 10 seconds later. On non-Windows platforms, the default behaviour of |
|
|
|
`SIGHUP` is to terminate node, but once a listener has been installed its |
|
|
|
default behaviour will be removed. |
|
|
|
listener installed, however io.js will be unconditionally terminated by |
|
|
|
Windows about 10 seconds later. On non-Windows platforms, the default |
|
|
|
behaviour of `SIGHUP` is to terminate io.js, but once a listener has been |
|
|
|
installed its default behaviour 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 |
|
|
|
generated with `CTRL+C` (though this may be configurable). It is not generated |
|
|
@ -161,10 +161,10 @@ Note: |
|
|
|
only happen on write to the console when the cursor is being moved, or when a |
|
|
|
readable tty is used in raw mode. |
|
|
|
- `SIGKILL` cannot have a listener installed, it will unconditionally terminate |
|
|
|
node on all platforms. |
|
|
|
io.js on all platforms. |
|
|
|
- `SIGSTOP` cannot have a listener installed. |
|
|
|
|
|
|
|
Note that Windows does not support sending Signals, but node offers some |
|
|
|
Note that Windows does not support sending Signals, but io.js offers some |
|
|
|
emulation with `process.kill()`, and `child_process.kill()`: |
|
|
|
- Sending signal `0` can be used to search for the existence of a process |
|
|
|
- Sending `SIGINT`, `SIGTERM`, and `SIGKILL` cause the unconditional exit of the |
|
|
@ -180,7 +180,7 @@ Example: the definition of `console.log` |
|
|
|
process.stdout.write(d + '\n'); |
|
|
|
}; |
|
|
|
|
|
|
|
`process.stderr` and `process.stdout` are unlike other streams in Node in |
|
|
|
`process.stderr` and `process.stdout` are unlike other streams in io.js in |
|
|
|
that they cannot be closed (`end()` will throw), they never emit the `finish` |
|
|
|
event and that writes are usually blocking. |
|
|
|
|
|
|
@ -190,17 +190,17 @@ event and that writes are usually blocking. |
|
|
|
- They are blocking in Linux/Unix. |
|
|
|
- They are non-blocking like other streams in Windows. |
|
|
|
|
|
|
|
To check if Node is being run in a TTY context, read the `isTTY` property |
|
|
|
To check if io.js is being run in a TTY context, read the `isTTY` property |
|
|
|
on `process.stderr`, `process.stdout`, or `process.stdin`: |
|
|
|
|
|
|
|
$ node -p "Boolean(process.stdin.isTTY)" |
|
|
|
$ iojs -p "Boolean(process.stdin.isTTY)" |
|
|
|
true |
|
|
|
$ echo "foo" | node -p "Boolean(process.stdin.isTTY)" |
|
|
|
$ echo "foo" | iojs -p "Boolean(process.stdin.isTTY)" |
|
|
|
false |
|
|
|
|
|
|
|
$ node -p "Boolean(process.stdout.isTTY)" |
|
|
|
$ iojs -p "Boolean(process.stdout.isTTY)" |
|
|
|
true |
|
|
|
$ node -p "Boolean(process.stdout.isTTY)" | cat |
|
|
|
$ iojs -p "Boolean(process.stdout.isTTY)" | cat |
|
|
|
false |
|
|
|
|
|
|
|
See [the tty docs](tty.html#tty_tty) for more information. |
|
|
@ -209,7 +209,7 @@ See [the tty docs](tty.html#tty_tty) for more information. |
|
|
|
|
|
|
|
A writable stream to stderr (on fd `2`). |
|
|
|
|
|
|
|
`process.stderr` and `process.stdout` are unlike other streams in Node in |
|
|
|
`process.stderr` and `process.stdout` are unlike other streams in io.js in |
|
|
|
that they cannot be closed (`end()` will throw), they never emit the `finish` |
|
|
|
event and that writes are usually blocking. |
|
|
|
|
|
|
@ -240,7 +240,7 @@ Example of opening standard input and listening for both events: |
|
|
|
}); |
|
|
|
|
|
|
|
As a Stream, `process.stdin` can also be used in "old" mode that is compatible |
|
|
|
with scripts written for node prior v0.10. |
|
|
|
with scripts written for node.js prior to v0.10. |
|
|
|
For more information see |
|
|
|
[Stream compatibility](stream.html#stream_compatibility_with_older_node_versions). |
|
|
|
|
|
|
@ -254,7 +254,7 @@ mode over "old" one. |
|
|
|
## process.argv |
|
|
|
|
|
|
|
An array containing the command line arguments. The first element will be |
|
|
|
'node', the second element will be the name of the JavaScript file. The |
|
|
|
'iojs', the second element will be the name of the JavaScript file. The |
|
|
|
next elements will be any additional command line arguments. |
|
|
|
|
|
|
|
// print process.argv |
|
|
@ -264,9 +264,9 @@ next elements will be any additional command line arguments. |
|
|
|
|
|
|
|
This will generate: |
|
|
|
|
|
|
|
$ node process-2.js one two=three four |
|
|
|
0: node |
|
|
|
1: /Users/mjr/work/node/process-2.js |
|
|
|
$ iojs process-2.js one two=three four |
|
|
|
0: iojs |
|
|
|
1: /Users/mjr/work/iojs/process-2.js |
|
|
|
2: one |
|
|
|
3: two=three |
|
|
|
4: four |
|
|
@ -278,21 +278,21 @@ This is the absolute pathname of the executable that started the process. |
|
|
|
|
|
|
|
Example: |
|
|
|
|
|
|
|
/usr/local/bin/node |
|
|
|
/usr/local/bin/iojs |
|
|
|
|
|
|
|
|
|
|
|
## process.execArgv |
|
|
|
|
|
|
|
This is the set of node-specific command line options from the |
|
|
|
This is the set of io.js-specific command line options from the |
|
|
|
executable that started the process. These options do not show up in |
|
|
|
`process.argv`, and do not include the node executable, the name of |
|
|
|
`process.argv`, and do not include the io.js executable, the name of |
|
|
|
the script, or any options following the script name. These options |
|
|
|
are useful in order to spawn child processes with the same execution |
|
|
|
environment as the parent. |
|
|
|
|
|
|
|
Example: |
|
|
|
|
|
|
|
$ node --harmony script.js --version |
|
|
|
$ iojs --harmony script.js --version |
|
|
|
|
|
|
|
results in process.execArgv: |
|
|
|
|
|
|
@ -300,12 +300,12 @@ results in process.execArgv: |
|
|
|
|
|
|
|
and process.argv: |
|
|
|
|
|
|
|
['/usr/local/bin/node', 'script.js', '--version'] |
|
|
|
['/usr/local/bin/iojs', 'script.js', '--version'] |
|
|
|
|
|
|
|
|
|
|
|
## process.abort() |
|
|
|
|
|
|
|
This causes node to emit an abort. This will cause node to exit and |
|
|
|
This causes io.js to emit an abort. This will cause io.js to exit and |
|
|
|
generate a core file. |
|
|
|
|
|
|
|
## process.chdir(directory) |
|
|
@ -345,12 +345,12 @@ An example of this object looks like: |
|
|
|
SHLVL: '1', |
|
|
|
HOME: '/Users/maciej', |
|
|
|
LOGNAME: 'maciej', |
|
|
|
_: '/usr/local/bin/node' } |
|
|
|
_: '/usr/local/bin/iojs' } |
|
|
|
|
|
|
|
You can write to this object, but changes won't be reflected outside of your |
|
|
|
process. That means that the following won't work: |
|
|
|
|
|
|
|
node -e 'process.env.foo = "bar"' && echo $foo |
|
|
|
$ iojs -e 'process.env.foo = "bar"' && echo $foo |
|
|
|
|
|
|
|
But this will: |
|
|
|
|
|
|
@ -367,7 +367,7 @@ To exit with a 'failure' code: |
|
|
|
|
|
|
|
process.exit(1); |
|
|
|
|
|
|
|
The shell that executed node should see the exit code as 1. |
|
|
|
The shell that executed io.js should see the exit code as 1. |
|
|
|
|
|
|
|
|
|
|
|
## process.exitCode |
|
|
@ -454,7 +454,7 @@ Note: this function is only available on POSIX platforms (i.e. not Windows, |
|
|
|
Android) |
|
|
|
|
|
|
|
Returns an array with the supplementary group IDs. POSIX leaves it unspecified |
|
|
|
if the effective group ID is included but node.js ensures it always is. |
|
|
|
if the effective group ID is included but io.js ensures it always is. |
|
|
|
|
|
|
|
|
|
|
|
## process.setgroups(groups) |
|
|
@ -496,7 +496,7 @@ A compiled-in property that exposes `NODE_VERSION`. |
|
|
|
|
|
|
|
## process.versions |
|
|
|
|
|
|
|
A property exposing version strings of node and its dependencies. |
|
|
|
A property exposing version strings of io.js and its dependencies. |
|
|
|
|
|
|
|
console.log(process.versions); |
|
|
|
|
|
|
@ -514,7 +514,7 @@ Will print something like: |
|
|
|
## process.config |
|
|
|
|
|
|
|
An Object containing the JavaScript representation of the configure options |
|
|
|
that were used to compile the current node executable. This is the same as |
|
|
|
that were used to compile the current io.js executable. This is the same as |
|
|
|
the "config.gypi" file that was produced when running the `./configure` script. |
|
|
|
|
|
|
|
An example of the possible output looks like: |
|
|
@ -568,7 +568,7 @@ Example of sending a signal to yourself: |
|
|
|
|
|
|
|
process.kill(process.pid, 'SIGHUP'); |
|
|
|
|
|
|
|
Note: When SIGUSR1 is received by Node.js it starts the debugger, see |
|
|
|
Note: When SIGUSR1 is received by io.js it starts the debugger, see |
|
|
|
[Signal Events](#process_signal_events). |
|
|
|
|
|
|
|
## process.pid |
|
|
@ -610,7 +610,7 @@ What platform you're running on: |
|
|
|
|
|
|
|
## process.memoryUsage() |
|
|
|
|
|
|
|
Returns an object describing the memory usage of the Node process |
|
|
|
Returns an object describing the memory usage of the io.js process |
|
|
|
measured in bytes. |
|
|
|
|
|
|
|
var util = require('util'); |
|
|
@ -717,7 +717,7 @@ given, otherwise returns the current mask. |
|
|
|
|
|
|
|
## process.uptime() |
|
|
|
|
|
|
|
Number of seconds Node has been running. |
|
|
|
Number of seconds io.js has been running. |
|
|
|
|
|
|
|
|
|
|
|
## process.hrtime() |
|
|
|