|
|
@ -880,10 +880,9 @@ if (someConditionNotMet()) { |
|
|
|
``` |
|
|
|
|
|
|
|
The reason this is problematic is because writes to `process.stdout` in Node.js |
|
|
|
are usually *non-blocking* and may occur over multiple ticks of the Node.js |
|
|
|
event loop. |
|
|
|
Calling `process.exit()`, however, forces the process to exit *before* those |
|
|
|
additional writes to `stdout` can be performed. |
|
|
|
are sometimes *non-blocking* and may occur over multiple ticks of the Node.js |
|
|
|
event loop. Calling `process.exit()`, however, forces the process to exit |
|
|
|
*before* those additional writes to `stdout` can be performed. |
|
|
|
|
|
|
|
Rather than calling `process.exit()` directly, the code *should* set the |
|
|
|
`process.exitCode` and allow the process to exit naturally by avoiding |
|
|
@ -1451,15 +1450,20 @@ Android) |
|
|
|
The `process.stderr` property returns a [Writable][] stream equivalent to or |
|
|
|
associated with `stderr` (fd `2`). |
|
|
|
|
|
|
|
`process.stderr` and `process.stdout` are unlike other streams in Node.js in |
|
|
|
that they cannot be closed (calling [`end()`][] will throw an Error), they never |
|
|
|
emit the [`'finish'`][] event, and writes can block when output is redirected to |
|
|
|
a file (although disks are fast and operating systems normally employ write-back |
|
|
|
caching so it should be a very rare occurrence indeed.) |
|
|
|
Note: `process.stderr` and `process.stdout` differ from other Node.js streams |
|
|
|
in several ways: |
|
|
|
1. They cannot be closed ([`end()`][] will throw). |
|
|
|
2. They never emit the [`'finish'`][] event. |
|
|
|
3. Writes _can_ block when output is redirected to a file. |
|
|
|
- Note that disks are fast and operating systems normally employ write-back |
|
|
|
caching so this is very uncommon. |
|
|
|
4. Writes on UNIX __will__ block by default if output is going to a TTY |
|
|
|
(a terminal). |
|
|
|
5. Windows functionality differs. Writes block except when output is going to a |
|
|
|
TTY. |
|
|
|
|
|
|
|
Additionally, `process.stderr` and `process.stdout` are blocking when outputting |
|
|
|
to TTYs (terminals) on OS X as a workaround for the OS's very small, 1kb |
|
|
|
buffer size. This is to prevent interleaving between `stdout` and `stderr`. |
|
|
|
To check if Node.js is being run in a TTY context, read the `isTTY` property |
|
|
|
on `process.stderr`, `process.stdout`, or `process.stdin`: |
|
|
|
|
|
|
|
## process.stdin |
|
|
|
|
|
|
@ -1504,11 +1508,17 @@ console.log = (msg) => { |
|
|
|
}; |
|
|
|
``` |
|
|
|
|
|
|
|
`process.stderr` and `process.stdout` are unlike other streams in Node.js in |
|
|
|
that they cannot be closed (calling [`end()`][] will throw an Error), they never |
|
|
|
emit the [`'finish'`][] event and that writes can block when output is |
|
|
|
redirected to a file (although disks are fast and operating systems normally |
|
|
|
employ write-back caching so it should be a very rare occurrence indeed.) |
|
|
|
Note: `process.stderr` and `process.stdout` differ from other Node.js streams |
|
|
|
in several ways: |
|
|
|
1. They cannot be closed ([`end()`][] will throw). |
|
|
|
2. They never emit the [`'finish'`][] event. |
|
|
|
3. Writes _can_ block when output is redirected to a file. |
|
|
|
- Note that disks are fast and operating systems normally employ write-back |
|
|
|
caching so this is very uncommon. |
|
|
|
4. Writes on UNIX __will__ block by default if output is going to a TTY |
|
|
|
(a terminal). |
|
|
|
5. Windows functionality differs. Writes block except when output is going to a |
|
|
|
TTY. |
|
|
|
|
|
|
|
To check if Node.js is being run in a TTY context, read the `isTTY` property |
|
|
|
on `process.stderr`, `process.stdout`, or `process.stdin`: |
|
|
|