@@ -880,10 +880,9 @@ if (someConditionNotMet()) {
880
880
```
881
881
882
882
The reason this is problematic is because writes to ` process.stdout ` in Node.js
883
- are usually * non-blocking* and may occur over multiple ticks of the Node.js
884
- event loop.
885
- Calling ` process.exit() ` , however, forces the process to exit * before* those
886
- additional writes to ` stdout ` can be performed.
883
+ are sometimes * non-blocking* and may occur over multiple ticks of the Node.js
884
+ event loop. Calling ` process.exit() ` , however, forces the process to exit
885
+ * before* those additional writes to ` stdout ` can be performed.
887
886
888
887
Rather than calling ` process.exit() ` directly, the code * should* set the
889
888
` process.exitCode ` and allow the process to exit naturally by avoiding
@@ -1451,15 +1450,20 @@ Android)
1451
1450
The ` process.stderr ` property returns a [ Writable] [ ] stream equivalent to or
1452
1451
associated with ` stderr ` (fd ` 2 ` ).
1453
1452
1454
- ` process.stderr ` and ` process.stdout ` are unlike other streams in Node.js in
1455
- that they cannot be closed (calling [ ` end() ` ] [ ] will throw an Error), they never
1456
- emit the [ ` 'finish' ` ] [ ] event, and writes can block when output is redirected to
1457
- a file (although disks are fast and operating systems normally employ write-back
1458
- caching so it should be a very rare occurrence indeed.)
1453
+ Note: ` process.stderr ` and ` process.stdout ` differ from other Node.js streams
1454
+ in several ways:
1455
+ 1 . They cannot be closed ([ ` end() ` ] [ ] will throw).
1456
+ 2 . They never emit the [ ` 'finish' ` ] [ ] event.
1457
+ 3 . Writes _ can_ block when output is redirected to a file.
1458
+ - Note that disks are fast and operating systems normally employ write-back
1459
+ caching so this is very uncommon.
1460
+ 4 . Writes on UNIX __ will__ block by default if output is going to a TTY
1461
+ (a terminal).
1462
+ 5 . Windows functionality differs. Writes block except when output is going to a
1463
+ TTY.
1459
1464
1460
- Additionally, ` process.stderr ` and ` process.stdout ` are blocking when outputting
1461
- to TTYs (terminals) on OS X as a workaround for the OS's very small, 1kb
1462
- buffer size. This is to prevent interleaving between ` stdout ` and ` stderr ` .
1465
+ To check if Node.js is being run in a TTY context, read the ` isTTY ` property
1466
+ on ` process.stderr ` , ` process.stdout ` , or ` process.stdin ` :
1463
1467
1464
1468
## process.stdin
1465
1469
@@ -1504,11 +1508,17 @@ console.log = (msg) => {
1504
1508
};
1505
1509
```
1506
1510
1507
- ` process.stderr ` and ` process.stdout ` are unlike other streams in Node.js in
1508
- that they cannot be closed (calling [ ` end() ` ] [ ] will throw an Error), they never
1509
- emit the [ ` 'finish' ` ] [ ] event and that writes can block when output is
1510
- redirected to a file (although disks are fast and operating systems normally
1511
- employ write-back caching so it should be a very rare occurrence indeed.)
1511
+ Note: ` process.stderr ` and ` process.stdout ` differ from other Node.js streams
1512
+ in several ways:
1513
+ 1 . They cannot be closed ([ ` end() ` ] [ ] will throw).
1514
+ 2 . They never emit the [ ` 'finish' ` ] [ ] event.
1515
+ 3 . Writes _ can_ block when output is redirected to a file.
1516
+ - Note that disks are fast and operating systems normally employ write-back
1517
+ caching so this is very uncommon.
1518
+ 4 . Writes on UNIX __ will__ block by default if output is going to a TTY
1519
+ (a terminal).
1520
+ 5 . Windows functionality differs. Writes block except when output is going to a
1521
+ TTY.
1512
1522
1513
1523
To check if Node.js is being run in a TTY context, read the ` isTTY ` property
1514
1524
on ` process.stderr ` , ` process.stdout ` , or ` process.stdin ` :
0 commit comments