From da5716ea8f13307d032fc64ee098f5f1735ea422 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 13 Apr 2017 04:31:39 +0300 Subject: [PATCH 1/5] doc: replace `var` by `const` in process.md --- doc/api/process.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index 306f555e4fcfce..9760f91a8e0005 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -249,7 +249,7 @@ function SomeResource() { this.loaded = Promise.reject(new Error('Resource not yet loaded!')); } -var resource = new SomeResource(); +const resource = new SomeResource(); // no .catch or .then on resource.loaded for at least a turn ``` @@ -310,7 +310,7 @@ adds a custom handler to the `'warning'` event: ```txt $ node --no-warnings -> var p = process.on('warning', (warning) => console.warn('Do not do that!')); +> const p = process.on('warning', (warning) => console.warn('Do not do that!')); > events.defaultMaxListeners = 1; > process.on('foo', () => {}); > process.on('foo', () => {}); @@ -1053,11 +1053,11 @@ drift. The primary use is for measuring performance between intervals: ```js const NS_PER_SEC = 1e9; -var time = process.hrtime(); +const time = process.hrtime(); // [ 1800216, 25 ] setTimeout(() => { - var diff = process.hrtime(time); + const diff = process.hrtime(time); // [ 1, 552 ] console.log(`Benchmark took ${diff[0] * NS_PER_SEC + diff[1]} nanoseconds`); @@ -1232,7 +1232,7 @@ function MyThing(options) { }); } -var thing = new MyThing(); +const thing = new MyThing(); thing.getReadyForStuff(); // thing.startDoingStuff() gets called now, not before. @@ -1535,7 +1535,7 @@ For example: process.stdin.setEncoding('utf8'); process.stdin.on('readable', () => { - var chunk = process.stdin.read(); + const chunk = process.stdin.read(); if (chunk !== null) { process.stdout.write(`data: ${chunk}`); } From 7fe3309aa8b5f54dd26e044104cae69996d3fe19 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 13 Apr 2017 04:32:49 +0300 Subject: [PATCH 2/5] doc: use console.error() in process.md --- doc/api/process.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/process.md b/doc/api/process.md index 9760f91a8e0005..d6b72e1e73a268 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -511,7 +511,7 @@ try { console.log(`New directory: ${process.cwd()}`); } catch (err) { - console.log(`chdir: ${err}`); + console.error(`chdir: ${err}`); } ``` From d51776e10b37d77e2006f6c4a0241bb950d1e78a Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 13 Apr 2017 04:34:12 +0300 Subject: [PATCH 3/5] doc: fix example file name mismatch in process.md --- doc/api/process.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index d6b72e1e73a268..a0f9c47a1c258b 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -452,14 +452,14 @@ process.argv.forEach((val, index) => { Launching the Node.js process as: ```console -$ node process-2.js one two=three four +$ node process-args.js one two=three four ``` Would generate the output: ```text 0: /usr/local/bin/node -1: /Users/mjr/work/node/process-2.js +1: /Users/mjr/work/node/process-args.js 2: one 3: two=three 4: four From 3d613294f63a85717f0b097ab9f5ab328cd7904f Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 13 Apr 2017 04:39:04 +0300 Subject: [PATCH 4/5] doc: update output examples in process.md --- doc/api/process.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index a0f9c47a1c258b..57e7d164243a45 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -301,8 +301,8 @@ $ node > events.defaultMaxListeners = 1; > process.on('foo', () => {}); > process.on('foo', () => {}); -> (node:38638) Warning: Possible EventEmitter memory leak detected. 2 foo -... listeners added. Use emitter.setMaxListeners() to increase limit +> (node:38638) MaxListenersExceededWarning: Possible EventEmitter memory leak +detected. 2 foo listeners added. Use emitter.setMaxListeners() to increase limit ``` In contrast, the following example turns off the default warning output and @@ -668,7 +668,7 @@ process.emitWarning('Something Happened!', 'CustomWarning'); ```js process.emitWarning('Something happened!', 'CustomWarning', 'WARN001'); -// Emits: (node:56338) CustomWarning [WARN001]: Something Happened! +// Emits: (node:56338) [WARN001] CustomWarning: Something happened! ``` In each of the previous examples, an `Error` object is generated internally by @@ -696,7 +696,7 @@ myWarning.name = 'CustomWarning'; myWarning.code = 'WARN001'; process.emitWarning(myWarning); -// Emits: (node:56338) CustomWarning [WARN001]: Warning! Something Happened! +// Emits: (node:56338) [WARN001] CustomWarning: Warning! Something happened! ``` A `TypeError` is thrown if `warning` is anything other than a string or `Error` From 35479078701a470c18860d0068567ae955b1f682 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 13 Apr 2017 04:41:34 +0300 Subject: [PATCH 5/5] doc: increase output readability in process.md Add a line break, remove an unnecessary duplicate word. --- doc/api/process.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index 57e7d164243a45..5df5c5830a9b21 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -162,7 +162,7 @@ For example: ```js process.on('uncaughtException', (err) => { - fs.writeSync(1, `Caught exception: ${err}`); + fs.writeSync(1, `Caught exception: ${err}\n`); }); setTimeout(() => { @@ -231,7 +231,7 @@ For example: ```js process.on('unhandledRejection', (reason, p) => { - console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); + console.log('Unhandled Rejection at:', p, 'reason:', reason); // application specific logging, throwing an error, or other logic here });