@@ -162,7 +162,7 @@ For example:
162
162
163
163
``` js
164
164
process .on (' uncaughtException' , (err ) => {
165
- fs .writeSync (1 , ` Caught exception: ${ err} ` );
165
+ fs .writeSync (1 , ` Caught exception: ${ err} \n ` );
166
166
});
167
167
168
168
setTimeout (() => {
@@ -231,7 +231,7 @@ For example:
231
231
232
232
``` js
233
233
process .on (' unhandledRejection' , (reason , p ) => {
234
- console .log (' Unhandled Rejection at: Promise ' , p, ' reason:' , reason);
234
+ console .log (' Unhandled Rejection at:' , p, ' reason:' , reason);
235
235
// application specific logging, throwing an error, or other logic here
236
236
});
237
237
@@ -249,7 +249,7 @@ function SomeResource() {
249
249
this .loaded = Promise .reject (new Error (' Resource not yet loaded!' ));
250
250
}
251
251
252
- var resource = new SomeResource ();
252
+ const resource = new SomeResource ();
253
253
// no .catch or .then on resource.loaded for at least a turn
254
254
```
255
255
@@ -301,16 +301,16 @@ $ node
301
301
> events.defaultMaxListeners = 1;
302
302
> process.on('foo', () => {});
303
303
> process.on('foo', () => {});
304
- > (node:38638) Warning : Possible EventEmitter memory leak detected. 2 foo
305
- ... listeners added. Use emitter.setMaxListeners() to increase limit
304
+ > (node:38638) MaxListenersExceededWarning : Possible EventEmitter memory leak
305
+ detected. 2 foo listeners added. Use emitter.setMaxListeners() to increase limit
306
306
```
307
307
308
308
In contrast, the following example turns off the default warning output and
309
309
adds a custom handler to the ` 'warning' ` event:
310
310
311
311
``` txt
312
312
$ node --no-warnings
313
- > var p = process.on('warning', (warning) => console.warn('Do not do that!'));
313
+ > const p = process.on('warning', (warning) => console.warn('Do not do that!'));
314
314
> events.defaultMaxListeners = 1;
315
315
> process.on('foo', () => {});
316
316
> process.on('foo', () => {});
@@ -452,14 +452,14 @@ process.argv.forEach((val, index) => {
452
452
Launching the Node.js process as:
453
453
454
454
``` console
455
- $ node process-2 .js one two=three four
455
+ $ node process-args .js one two=three four
456
456
```
457
457
458
458
Would generate the output:
459
459
460
460
``` text
461
461
0: /usr/local/bin/node
462
- 1: /Users/mjr/work/node/process-2 .js
462
+ 1: /Users/mjr/work/node/process-args .js
463
463
2: one
464
464
3: two=three
465
465
4: four
@@ -511,7 +511,7 @@ try {
511
511
console .log (` New directory: ${ process .cwd ()} ` );
512
512
}
513
513
catch (err) {
514
- console .log (` chdir: ${ err} ` );
514
+ console .error (` chdir: ${ err} ` );
515
515
}
516
516
```
517
517
@@ -668,7 +668,7 @@ process.emitWarning('Something Happened!', 'CustomWarning');
668
668
669
669
``` js
670
670
process .emitWarning (' Something happened!' , ' CustomWarning' , ' WARN001' );
671
- // Emits: (node:56338) CustomWarning [WARN001]: Something Happened !
671
+ // Emits: (node:56338) [WARN001] CustomWarning : Something happened !
672
672
```
673
673
674
674
In each of the previous examples, an ` Error ` object is generated internally by
@@ -696,7 +696,7 @@ myWarning.name = 'CustomWarning';
696
696
myWarning .code = ' WARN001' ;
697
697
698
698
process .emitWarning (myWarning);
699
- // Emits: (node:56338) CustomWarning [WARN001]: Warning! Something Happened !
699
+ // Emits: (node:56338) [WARN001] CustomWarning : Warning! Something happened !
700
700
```
701
701
702
702
A ` TypeError ` is thrown if ` warning ` is anything other than a string or ` Error `
@@ -1053,11 +1053,11 @@ drift. The primary use is for measuring performance between intervals:
1053
1053
1054
1054
``` js
1055
1055
const NS_PER_SEC = 1e9 ;
1056
- var time = process .hrtime ();
1056
+ const time = process .hrtime ();
1057
1057
// [ 1800216, 25 ]
1058
1058
1059
1059
setTimeout (() => {
1060
- var diff = process .hrtime (time);
1060
+ const diff = process .hrtime (time);
1061
1061
// [ 1, 552 ]
1062
1062
1063
1063
console .log (` Benchmark took ${ diff[0 ] * NS_PER_SEC + diff[1 ]} nanoseconds` );
@@ -1232,7 +1232,7 @@ function MyThing(options) {
1232
1232
});
1233
1233
}
1234
1234
1235
- var thing = new MyThing ();
1235
+ const thing = new MyThing ();
1236
1236
thing .getReadyForStuff ();
1237
1237
1238
1238
// thing.startDoingStuff() gets called now, not before.
@@ -1535,7 +1535,7 @@ For example:
1535
1535
process .stdin .setEncoding (' utf8' );
1536
1536
1537
1537
process .stdin .on (' readable' , () => {
1538
- var chunk = process .stdin .read ();
1538
+ const chunk = process .stdin .read ();
1539
1539
if (chunk !== null ) {
1540
1540
process .stdout .write (` data: ${ chunk} ` );
1541
1541
}
0 commit comments